Skip to content

Commit 353bf56

Browse files
port19xCoolnsX71zenith
authored
fix: hex decryption (#1171)
Co-authored-by: coolnsx <[email protected]> Co-authored-by: zen <[email protected]>
1 parent 967dcdd commit 353bf56

File tree

2 files changed

+55
-43
lines changed

2 files changed

+55
-43
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ cd .. && rm -rf ./ani-cli
154154
*To install (with Homebrew) the dependencies required on Mac OS, you can run:*
155155

156156
```sh
157-
brew install curl grep aria2 ffmpeg git fzf && \
157+
brew install curl grep aria2 ffmpeg git fzf yt-dlp && \
158158
brew install --cask iina
159159
```
160160
*Why iina and not mpv? Drop-in replacement for mpv for MacOS. Integrates well with OSX UI. Excellent support for M1. Open Source.*
@@ -259,6 +259,9 @@ tar xvf ~/.aria2c/aria2-1.36.0.tar.bz2 -C ~/.aria2c/
259259
cp ~/.aria2c/aria2-1.36.0-linux-gnu-64bit-build1/aria2c ~/.local/bin/
260260
chmod +x ~/.local/bin/aria2c
261261

262+
curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o ~/.local/bin/yt-dlp
263+
chmod +x ~/.local/bin/yt-dlp
264+
262265
git clone https://github.com/pystardust/ani-cli.git ~/.ani-cli
263266
cp ~/.ani-cli/ani-cli ~/.local/bin/
264267

@@ -299,6 +302,13 @@ cp ~/.aria2c/aria2-1.36.0-linux-gnu-64bit-build1/aria2c ~/.local/bin/
299302
chmod +x ~/.local/bin/aria2c
300303
```
301304

305+
##### Install [yt-dlp](https://github.com/yt-dlp/yt-dlp) (needed for download feature only):
306+
307+
```sh
308+
curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o ~/.local/bin/yt-dlp
309+
chmod +x ~/.local/bin/yt-dlp
310+
```
311+
302312
##### Install ani-cli:
303313

304314
```sh
@@ -380,6 +390,7 @@ rm -rf ~/.ani-cli
380390
optionally: remove dependencies:
381391
```sh
382392
rm ~/.local/bin/aria2c
393+
rm ~/.local/bin/yt-dlp
383394
rm -rf "~/.aria2"
384395
rm -rf "~/.fzf"
385396
flatpak uninstall io.mpv.Mpv
@@ -405,7 +416,8 @@ apk del grep sed curl fzf git aria2 alpine-sdk ncurses
405416
- mpv - Video Player
406417
- iina - mpv replacement for MacOS
407418
- aria2c - Download manager
408-
- ffmpeg - m3u8 Downloader
419+
- yt-dlp - m3u8 Downloader
420+
- ffmpeg - m3u8 Downloader (fallback)
409421
- fzf - User interface
410422

411423
## Homies

ani-cli

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

3-
version_number="4.4.5"
3+
version_number="4.5.0"
44

55
# UI
66

@@ -106,7 +106,7 @@ dep_ch() {
106106

107107
# extract the video links from reponse of embed urls, extract mp4 links form m3u8 lists
108108
get_links() {
109-
episode_link="$(curl -e "https://${allanime_base}" -s --cipher "AES256-SHA256" "https://allanimenews.com$*" -A "$agent" | sed 's|},{|\n|g' | sed -nE 's|.*link":"([^"]*)".*"resolutionStr":"([^"]*)".*|\2 >\1|p;s|.*hls","url":"([^"]*)".*"hardsub_lang":"en-US".*|\1|p')"
109+
episode_link="$(curl -e "$allanime_base" -s --cipher "AES256-SHA256" "https://embed.ssbcontent.site$*" -A "$agent" | sed 's|},{|\n|g' | sed -nE 's|.*link":"([^"]*)".*"resolutionStr":"([^"]*)".*|\2 >\1|p;s|.*hls","url":"([^"]*)".*"hardsub_lang":"en-US".*|\1|p')"
110110
case "$episode_link" in
111111
*repackager.wixmp.com*)
112112
extract_link=$(printf "%s" "$episode_link" | cut -d'>' -f2 | sed 's|repackager.wixmp.com/||g;s|\.urlset.*||g')
@@ -120,12 +120,12 @@ get_links() {
120120
else
121121
extract_link=$(printf "%s" "$episode_link" | head -1 | cut -d'>' -f2)
122122
relative_link=$(printf "%s" "$extract_link" | sed 's|[^/]*$||')
123-
curl -e "https://${allanime_base}/" -s --cipher "AES256-SHA256" "$extract_link" -A "$agent" | sed 's|^#.*x||g; s|,.*|p|g; /^#/d; $!N; s|\n| >|' | sed "s|>|>${relative_link}|g" | sort -nr
123+
curl -e "$allanime_base" -s --cipher "AES256-SHA256" "$extract_link" -A "$agent" | sed 's|^#.*x||g; s|,.*|p|g; /^#/d; $!N; s|\n| >|' | sed "s|>|>${relative_link}|g" | sort -nr
124124
fi
125125
;;
126126
*) [ -n "$episode_link" ] && printf "%s\n" "$episode_link" ;;
127127
esac
128-
printf "\033[1;32m %s\033[0m Links Fetched\n" "$provider_name" 1>&2
128+
printf "\033[1;32m%s\033[0m Links Fetched\n" "$provider_name" 1>&2
129129
}
130130

131131
# innitialises provider_name and provider_id. First argument is the provider name, 2nd is the regex that matches that provider's link
@@ -134,20 +134,16 @@ provider_init() {
134134
provider_id=$(printf "%s" "$resp" | sed -n "$2" | head -1 | cut -d':' -f2)
135135
}
136136

137-
hex_to_ascii() {
138-
hex="$1"
139-
len=$(printf "%s" "$hex" | wc -c)
140-
ascii=""
141-
i=1
142-
while [ "$i" -lt "$len" ]; do
143-
char=$(printf "%s" "$hex" | cut -c "$i-$((i + 1))")
144-
dec=$(printf "%d" "0x$char")
145-
oct=$(printf "%03o" "$dec")
146-
# shellcheck disable=SC2059
147-
ascii="$ascii$(printf "\\$oct")"
148-
i=$((i + 2))
137+
decrypt_allanime() {
138+
printf "%s" "$-" | grep -q 'x' && set +x
139+
for hex in $(printf '%s' "$1" | sed 's/../&\n/g'); do
140+
dec=$(printf '%d' "0x$hex")
141+
xor=$((dec ^ 48))
142+
oct=$(printf "%03o" "$xor")
143+
#shellcheck disable=SC2059
144+
printf "\\$oct"
149145
done
150-
printf "%s" "$ascii"
146+
printf "%s" "$-" | grep -q 'x' || set -x
151147
}
152148

153149
# generates links based on given provider
@@ -156,12 +152,11 @@ generate_link() {
156152
1) provider_init "wixmp" "/Default :/p" ;; # wixmp(default)(m3u8)(multi) -> (mp4)(multi)
157153
2) provider_init "dropbox" "/Sak :/p" ;; # dropbox(mp4)(single)
158154
3) provider_init "wetransfer" "/Kir :/p" ;; # wetransfer(mp4)(single)
159-
4) provider_init "pstatic" "/Default B :/p" ;; # pstatic(default backup)(mp4)(multi)
160-
5) provider_init "sharepoint" "/S-mp4 :/p" ;; # sharepoint(mp4)(single)
155+
4) provider_init "sharepoint" "/S-mp4 :/p" ;; # sharepoint(mp4)(single)
156+
5) provider_init "rab" "/Rab :/p" ;; # rab(mp4)(multi)
161157
*) provider_init "gogoanime" "/Luf-mp4 :/p" ;; # gogoanime(m3u8)(multi)
162158
esac
163-
bin=$(hex_to_ascii "$provider_id")
164-
provider_id="$(printf "%s" "$bin" | sed "s/\/clock/\/clock\.json/")"
159+
provider_id="$(decrypt_allanime "$provider_id" | sed "s/\/clock/\/clock\.json/")"
165160
[ -n "$provider_id" ] && get_links "$provider_id"
166161
}
167162

@@ -180,10 +175,11 @@ get_episode_url() {
180175
# get the embed urls of the selected episode
181176
episode_embed_gql="query (\$showId: String!, \$translationType: VaildTranslationTypeEnumType!, \$episodeString: String!) { episode( showId: \$showId translationType: \$translationType episodeString: \$episodeString ) { episodeString sourceUrls }}"
182177

183-
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":"#([^"]*)".*sourceName":"([^"]*)".*|\2 :\1|p')
178+
resp=$(curl -e "$allanime_base" -s --cipher "AES256-SHA256" -G "${allanime_api}/api" --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":"##([^"]*)".*sourceName":"([^"]*)".*|\2 :\1|p')
184179
# generate links into sequential files
185180
provider=1
186181
i=0
182+
rm -f "$cache_dir/*"
187183
while [ "$i" -lt 6 ]; do
188184
generate_link "$provider" >"$cache_dir"/"$i" &
189185
provider=$((provider % 6 + 1))
@@ -200,14 +196,14 @@ get_episode_url() {
200196
search_anime() {
201197
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 } }}"
202198

203-
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"
199+
curl -e "$allanime_base" -s --cipher "AES256-SHA256" -G "${allanime_api}/api" --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"
204200
}
205201

206202
# get the episodes list of the selected anime
207203
episodes_list() {
208204
episodes_list_gql="query (\$showId: String!) { show( _id: \$showId ) { _id availableEpisodesDetail }}"
209205

210-
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
206+
curl -e "$allanime_base" -s --cipher AES256-SHA256 -G "${allanime_api}/api" --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
211207
}
212208

213209
# PLAYING
@@ -231,8 +227,8 @@ update_history() {
231227
download() {
232228
case $1 in
233229
*m3u8*)
234-
if command -v "hls"; then
235-
hls -ro "$download_dir/$2" "$1"
230+
if command -v "yt-dlp" >/dev/null; then
231+
yt-dlp "$1" --no-skip-unavailable-fragments --fragment-retries infinite -N 16 -o "$download_dir/$2.mp4"
236232
else
237233
ffmpeg -loglevel error -stats -i "$1" -c copy "$download_dir/$2.mp4"
238234
fi
@@ -247,14 +243,14 @@ play_episode() {
247243
[ -z "$episode" ] && get_episode_url
248244
case "$player_function" in
249245
debug) printf "All links:\n%s\nSelected link:\n%s\n" "$links" "$episode" ;;
250-
mpv*) nohup "$player_function" --force-media-title="${allanime_title}episode-${ep_no}-${mode}" "$episode" >/dev/null 2>&1 & ;;
246+
mpv*) nohup "$player_function" --force-media-title="${allanime_title}Episode ${ep_no}" "$episode" >/dev/null 2>&1 & ;;
251247
android_mpv) nohup am start --user 0 -a android.intent.action.VIEW -d "$episode" -n is.xyz.mpv/.MPVActivity >/dev/null 2>&1 & ;;
252-
android_vlc) nohup am start --user 0 -a android.intent.action.VIEW -d "$episode" -n org.videolan.vlc/org.videolan.vlc.gui.video.VideoPlayerActivity -e "title" "${allanime_title}episode-${ep_no}-${mode}" >/dev/null 2>&1 & ;;
253-
iina) nohup "$player_function" --no-stdin --keep-running --mpv-force-media-title="${allanime_title}episode-${ep_no}-${mode}" "$episode" >/dev/null 2>&1 & ;;
254-
flatpak_mpv) flatpak run io.mpv.Mpv --force-media-title="${allanime_title}episode-${ep_no}-${mode}" "$episode" >/dev/null 2>&1 & ;;
255-
vlc*) nohup "$player_function" --play-and-exit --meta-title="${allanime_title}episode-${ep_no}-${mode}" "$episode" >/dev/null 2>&1 & ;;
256-
*yncpla*) nohup "$player_function" "$episode" -- --force-media-title="${allanime_title}episode-${ep_no}-${mode}" >/dev/null 2>&1 & ;;
257-
download) "$player_function" "$episode" "${allanime_title}episode-${ep_no}-${mode}" ;;
248+
android_vlc) nohup am start --user 0 -a android.intent.action.VIEW -d "$episode" -n org.videolan.vlc/org.videolan.vlc.gui.video.VideoPlayerActivity -e "title" "${allanime_title}Episode ${ep_no}" >/dev/null 2>&1 & ;;
249+
iina) nohup "$player_function" --no-stdin --keep-running --mpv-force-media-title="${allanime_title}Episode ${ep_no}" "$episode" >/dev/null 2>&1 & ;;
250+
flatpak_mpv) flatpak run io.mpv.Mpv --force-media-title="${allanime_title}Episode ${ep_no}" "$episode" >/dev/null 2>&1 & ;;
251+
vlc*) nohup "$player_function" --play-and-exit --meta-title="${allanime_title}Episode ${ep_no}" "$episode" >/dev/null 2>&1 & ;;
252+
*yncpla*) nohup "$player_function" "$episode" -- --force-media-title="${allanime_title}Episode ${ep_no}" >/dev/null 2>&1 & ;;
253+
download) "$player_function" "$episode" "${allanime_title}Episode ${ep_no}" ;;
258254
catt) nohup catt cast "$episode" >/dev/null 2>&1 & ;;
259255
iSH)
260256
printf "\e]8;;vlc-x-callback://x-callback-url/stream?url=%s&filename=%sepisode-%s-%s\a~~~~~~~~~~~~~~~~~~~~\n~ Tap to open VLC ~\n~~~~~~~~~~~~~~~~~~~~\e]8;;\a\n" "$episode" "$allanime_title" "$ep_no" "$mode"
@@ -293,13 +289,16 @@ play() {
293289
else
294290
play_episode
295291
fi
292+
# moves upto stored positon and deletes to end
293+
[ "$player_function" != "debug" ] && [ "$player_function" != "download" ] && tput rc && tput ed
296294
}
297295

298296
# MAIN
299297

300298
# setup
301299
agent="Mozilla/5.0 (Windows NT 6.1; Win64; rv:109.0) Gecko/20100101 Firefox/109.0"
302-
allanime_base="allanime.to"
300+
allanime_base="https://allanime.to"
301+
allanime_api="https://api.allanime.day"
303302
mode="${ANI_CLI_MODE:-sub}"
304303
download_dir="${ANI_CLI_DOWNLOAD_DIR:-.}"
305304
quality="${ANI_CLI_QUALITY:-best}"
@@ -375,7 +374,7 @@ while [ $# -gt 0 ]; do
375374
esac
376375
shift
377376
done
378-
printf "\33[2K\r\033[1;34mChecking dependencies...\033[0m\n"
377+
printf "\33[2K\r\033[1;34mChecking dependencies...\033\n[0m"
379378
dep_ch "curl" "sed" "grep" "fzf" || true
380379
case "$player_function" in
381380
debug) ;;
@@ -384,8 +383,8 @@ case "$player_function" in
384383
dep_ch "flatpak"
385384
flatpak info io.mpv.Mpv >/dev/null 2>&1 || die "Program \"mpv (flatpak)\" not found. Please install it."
386385
;;
387-
android*) printf "Checking of players on Android is disabled\n" ;;
388-
*iSH*) printf "Checking of players on iOS is disabled\n" ;;
386+
android*) printf "\33[2K\rChecking of players on Android is disabled\n" ;;
387+
*iSH*) printf "\33[2K\rChecking of players on iOS is disabled\n" ;;
389388
*) dep_ch "$player_function" ;;
390389
esac
391390

@@ -402,13 +401,12 @@ case "$search" in
402401
read -r ep_no id title <"$resfile"
403402
ep_list=$(episodes_list "$id")
404403
ep_no=$(printf "%s" "$ep_list" | sed -n "/^${ep_no}$/{n;p;}") 2>/dev/null
405-
allanime_title="$(printf "%s" "$title" | cut -d'(' -f1 | tr -d '[:punct:]' | tr 'A-Z ' 'a-z-')"
406-
tput cuu1 && tput el
404+
allanime_title="$(printf "%s" "$title" | cut -d'(' -f1 | tr -d '[:punct:]')"
407405
;;
408406
*)
409407
if [ "$use_external_menu" = "0" ]; then
410408
while [ -z "$query" ]; do
411-
printf "Search anime: " && read -r query
409+
printf "\33[2K\r\033[1;36mSearch anime: \033[0m" && read -r query
412410
done
413411
else
414412
query=$(printf "" | external_menu "" "Search anime: ")
@@ -421,7 +419,7 @@ case "$search" in
421419
[ -z "$index" ] && result=$(printf "%s" "$anime_list" | nl -w 2 | sed 's/^[[:space:]]//' | nth "Select anime: ")
422420
[ -z "$result" ] && exit 1
423421
title=$(printf "%s" "$result" | cut -f2)
424-
allanime_title="$(printf "%s" "$title" | cut -d'(' -f1 | tr -d '[:punct:]' | tr 'A-Z ' 'a-z-')"
422+
allanime_title="$(printf "%s" "$title" | cut -d'(' -f1 | tr -d '[:punct:]')"
425423
id=$(printf "%s" "$result" | cut -f1)
426424
ep_list=$(episodes_list "$id")
427425
[ -z "$ep_no" ] && ep_no=$(printf "%s" "$ep_list" | nth "Select episode: " "$multi_selection_flag")
@@ -431,6 +429,8 @@ esac
431429

432430
# moves the cursor up one line and clears that line
433431
tput cuu1 && tput el
432+
# stores the positon of cursor
433+
tput sc
434434

435435
# playback & loop
436436
play

0 commit comments

Comments
 (0)