Last active
February 1, 2017 12:16
-
-
Save cympfh/b7912eae27a63bf76cbf8056acf8b014 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BASE=https://api.annict.com | |
CLIENT_ID=c81a73774111f942acf663d9204debe76cf07a15aca8745d9feff62276291e52 | |
CLIENT_SECRET=29a6e737db75badbb1a8b1867ef265ab18d2e2e406182c9dbc1981ce851a4669 | |
auth() { | |
REDIRECT_URI="urn:ietf:wg:oauth:2.0:oob" | |
URL="$BASE/oauth/authorize?client_id=$CLIENT_ID&response_type=code&redirect_uri=$REDIRECT_URI&scope=read%20write" | |
open -a 'Google Chrome' $URL | |
echo -n "auth code> " | |
read CODE | |
[ -d ~/.annict ] || mkdir ~/.annict | |
curl -F client_id=$CLIENT_ID -F client_secret=$CLIENT_SECRET -F grant_type=authorization_code -F redirect_uri=$REDIRECT_URI -F code=$CODE -X POST $BASE/oauth/token > ~/.annict/auth.json | |
} | |
get_token() { | |
jq -r .access_token ~/.annict/auth.json | |
} | |
unwatches() { | |
TOKEN=$(get_token) | |
curl -s "$BASE/v1/me/programs?per_page=50&filter_unwatched&access_token=$TOKEN" | jq -r '.programs[].work.title' | sort -u | |
} | |
check() { | |
EPISODE_ID=$1 | |
TOKEN=$(get_token) | |
COMMENT=$(date "+%Y-%m-%dT%H:%M") | |
curl -X POST "$BASE/v1/me/records?episode_id=$EPISODE_ID&comment=$COMMENT&access_token=$TOKEN&share_twitter=true" | |
} | |
# search work_id from title | |
search_work() { | |
TOKEN=$(get_token) | |
curl -s -X GET "$BASE/v1/works?fields=id,title&per_page=50&filter_title=$1&access_token=$TOKEN" | | |
jq -r '.works[] | "\(.id)\t\(.title)"' | |
} | |
# search episode_id from work_id | |
search_episode() { | |
TOKEN=$(get_token) | |
curl -s -X GET "$BASE/v1/episodes?fields=id,title,number_text,sort_number,work&per_page=50&filter_work_id=$1&access_token=$TOKEN" | | |
jq -r '.episodes[] | "\(.sort_number)\t\(.id)\t\(.number_text)\t\(.title)"' | | |
sort -n -k 1,1 | | |
sed 's/^[0-9]*[ \t]//g' | |
} | |
search_cli() { | |
search_work $1 | |
echo -n "work_id> " | |
read $ID | |
search_episode $ID | |
} | |
# search_cli ギャラクシーエンジェル | |
# search_episode 525 | |
check 41423 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment