Skip to content

Commit 7130e3d

Browse files
71zenithCoolnsXport19xDerisis13justchokingaround
authored
fix: allanime graphql (#1054)
Co-authored-by: coolnsx <[email protected]> Co-authored-by: port19 <[email protected]> Co-authored-by: Derisis13 <[email protected]> Co-authored-by: chokerman <[email protected]>
1 parent 8893edb commit 7130e3d

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- [ ] `-q` quality works
2323
- [ ] `-v` vlc works
2424
- [ ] `-e` select episode works
25+
- [ ] `-S` select index works
2526
- [ ] `-r` range selection works
2627
- [ ] `--dub` both work
2728
- [ ] all providers return links (not necessarily on a single anime, use debug mode to confirm)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</p>
2020

2121
<h3 align="center">
22-
A cli to browse and watch anime (alone AND with friends). This tool scrapes the site <a href="https://allanime.co/">allanime.</a>
22+
A cli to browse and watch anime (alone AND with friends). This tool scrapes the site <a href="https://allanime.to/">allanime.</a>
2323
</h3>
2424

2525
<h1 align="center">

ani-cli

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
version_number="4.1.4"
3+
version_number="4.2.0"
44

55
# UI
66

@@ -47,6 +47,8 @@ help_info() {
4747
Delete history
4848
-s, --syncplay
4949
Use Syncplay to watch with friends
50+
-S, --select-nth
51+
Select nth entry
5052
-q, --quality
5153
Specify the video quality
5254
-v, --vlc
@@ -159,7 +161,9 @@ select_quality() {
159161
# gets embed urls, collects direct links into provider files, selects one with desired quality into $episode
160162
get_episode_url() {
161163
# get the embed urls of the selected episode
162-
resp=$(curl -e "https://${allanime_base}" -s --cipher "AES256-SHA256" "https://api.${allanime_base}/allanimeapi?variables=%7B%22showId%22%3A%22$id%22%2C%22translationType%22%3A%22$mode%22%2C%22countryOrigin%22%3A%22ALL%22%2C%22episodeString%22%3A%22$ep_no%22%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%221f0a5d6c9ce6cd3127ee4efd304349345b0737fbf5ec33a60bbc3d18e3bb7c61%22%7D%7D" -A "$agent" | tr '{}' '\n' | sed 's|\\u002F|\/|g;s|\\||g' | sed -nE 's|.*sourceUrl":".*clock\?id=([^"]*)".*sourceName":"([^"]*)".*|\2 :\1|p')
164+
episode_embed_gql="query (\$showId: String!, \$translationType: VaildTranslationTypeEnumType!, \$episodeString: String!) { episode( showId: \$showId translationType: \$translationType episodeString: \$episodeString ) { episodeString sourceUrls }}"
165+
166+
resp=$(curl -e "https://${allanime_base}" -s --cipher "AES256-SHA256" -G "https://api.${allanime_base}/allanimeapi" --data-urlencode "variables={\"showId\":\"$id\",\"translationType\":\"$mode\",\"episodeString\":\"$ep_no\"}" --data-urlencode "query=$episode_embed_gql" -A "$agent" | tr '{}' '\n' | sed 's|\\u002F|\/|g;s|\\||g' | sed -nE 's|.*sourceUrl":".*clock\?id=([^"]*)".*sourceName":"([^"]*)".*|\2 :\1|p')
163167
# generate links into sequential files
164168
provider=1
165169
i=0
@@ -177,12 +181,16 @@ get_episode_url() {
177181

178182
# search the query and give results
179183
search_anime() {
180-
curl -e "https://${allanime_base}" -s --cipher "AES256-SHA256" "https://api.${allanime_base}/allanimeapi?variables=%7B%22search%22%3A%7B%22allowAdult%22%3Atrue%2C%22allowUnknown%22%3Atrue%2C%22query%22%3A%22$*%22%7D%2C%22limit%22%3A40%2C%22page%22%3A1%2C%22translationType%22%3A%22$mode%22%2C%22countryOrigin%22%3A%22ALL%22%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%229c7a8bc1e095a34f2972699e8105f7aaf9082c6e1ccd56eab99c2f1a971152c6%22%7D%7D" -A "$agent" | sed 's|Show|\n|g' | sed -nE "s|.*_id\":\"([^\"]*)\",\"name\":\"(.*)\",\"english.*\"$mode\":([1-9][^,]*).*|\1\t\2 (\3 episode)|p" | sed 's/\\//g;s/"//g'
184+
search_gql="query( \$search: SearchInput \$limit: Int \$page: Int \$translationType: VaildTranslationTypeEnumType \$countryOrigin: VaildCountryOriginEnumType ) { shows( search: \$search limit: \$limit page: \$page translationType: \$translationType countryOrigin: \$countryOrigin ) { edges { _id name availableEpisodes __typename } }}"
185+
186+
curl -e "https://${allanime_base}" -s --cipher "AES256-SHA256" -G "https://api.${allanime_base}/allanimeapi" --data-urlencode "variables={\"search\":{\"allowAdult\":false,\"allowUnknown\":false,\"query\":\"$1\"},\"limit\":40,\"page\":1,\"translationType\":\"$mode\",\"countryOrigin\":\"ALL\"}" --data-urlencode "query=$search_gql" -A "$agent" | sed 's|Show|\n|g' | sed -nE "s|.*_id\":\"([^\"]*)\",\"name\":\"([^\"]*)\".*${mode}\":([1-9][^,]*).*|\1\t\2 (\3 episodes)|p"
181187
}
182188

183189
# get the episodes list of the selected anime
184190
episodes_list() {
185-
curl -e "https://${allanime_base}" -s "https://api.${allanime_base}/allanimeapi?variables=%7B%22_id%22%3A%22$*%22%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%22f73a8347df0e3e794f8955a18de6e85ac25dfc6b74af8ad613edf87bb446a854%22%7D%7D" -A "$agent" | sed 's|\\||g' | sed -nE "s|.*$mode\":\[([0-9.\",]*)\].*|\1|p" | sed 's|,|\n|g; s|"||g' | sort -n -k 1
191+
episodes_list_gql="query (\$showId: String!) { show( _id: \$showId ) { _id availableEpisodesDetail }}"
192+
193+
curl -e "https://${allanime_base}" -s --cipher AES256-SHA256 -G "https://api.${allanime_base}/allanimeapi" --data-urlencode "variables={\"showId\":\"$*\"}" --data-urlencode "query=$episodes_list_gql" -A "$agent" | sed -nE "s|.*$mode\":\[([0-9.\",]*)\].*|\1|p" | sed 's|,|\n|g; s|"||g' | sort -n -k 1
186194
}
187195

188196
# PLAYING
@@ -232,9 +240,11 @@ play_episode() {
232240
}
233241

234242
play() {
235-
start=$(printf "%s" "$ep_no" | grep -Eo "^[0-9]+(\.[0-9])?")
236-
end=$(printf "%s" "$ep_no" | grep -Eo "[0-9]+(\.[0-9])?$")
243+
start=$(printf "%s" "$ep_no" | grep -Eo '^(-1|[0-9]+(\.[0-9])?)')
244+
end=$(printf "%s" "$ep_no" | grep -Eo '(-1|[0-9]+(\.[0-9])?)$')
245+
[ "$start" = "-1" ] && ep_no=$(printf "%s" "$ep_list" | tail -n1) && unset start
237246
[ -z "$end" ] || [ "$end" = "$start" ] && unset start end
247+
[ "$end" = "-1" ] && end=$(printf "%s" "$ep_list" | tail -n1)
238248
line_count=$(printf "%s\n" "$ep_no" | wc -l | tr -d "[:space:]")
239249
if [ "$line_count" != 1 ] || [ -n "$start" ]; then
240250
[ -z "$start" ] && start=$(printf "%s\n" "$ep_no" | head -n1)
@@ -301,6 +311,11 @@ while [ $# -gt 0 ]; do
301311
quality="$2"
302312
shift
303313
;;
314+
-S | --select-nth)
315+
[ $# -lt 2 ] && die "missing argument!"
316+
index="$2"
317+
shift
318+
;;
304319
-c | --continue) search=history ;;
305320
-d | --download) player_function=download ;;
306321
-D | --delete)
@@ -316,7 +331,7 @@ while [ $# -gt 0 ]; do
316331
;;
317332
--dub) mode="dub" ;;
318333
-U | --update) update_script ;;
319-
*) query="$(printf "%s" "$query $1" | sed "s|^ ||;s| |%20|g")" ;;
334+
*) query="$(printf "%s" "$query $1" | sed "s|^ ||;s| |+|g")" ;;
320335
esac
321336
shift
322337
done
@@ -358,10 +373,12 @@ history)
358373
query=$(: | external_menu "" "Search anime: ")
359374
fi
360375
done
361-
query=$(printf "%s" "$query" | sed "s| |%20|g")
376+
query=$(printf "%s" "$query" | sed "s| |+|g")
362377
anime_list=$(search_anime "$query")
363378
[ -z "$anime_list" ] && die "No results found!"
364-
result=$(printf "%s" "$anime_list" | nl -w 1 | nth "Select anime: ") || exit 1
379+
[ "$index" -eq "$index" ] 2>/dev/null && result=$(printf "%s" "$anime_list" | sed -n "${index}p")
380+
[ -z "$index" ] && result=$(printf "%s" "$anime_list" | nl -w 1 | nth "Select anime: ")
381+
[ -z "$result" ] && exit 1
365382
title=$(printf "%s" "$result" | cut -f2)
366383
allanime_title="$(printf "%s" "$title" | cut -d'(' -f1 | tr -d '[:punct:]' | tr 'A-Z ' 'a-z-')"
367384
id=$(printf "%s" "$result" | cut -f1)

ani-cli.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ Download episode.
2828
\fB\-D | --delete\fR
2929
Delete history.
3030
.TP
31+
\fB\-S | --select-nth\fR \fI\,<index>\/\fR
32+
Selects nth entry.
33+
.TP
3134
\fB\-h | --help\fR
3235
Show summary of options.
3336
.TP

0 commit comments

Comments
 (0)