From 13635cabf2cc2d1e12e35f760a18c9b97f7c3984 Mon Sep 17 00:00:00 2001 From: ksyasuda Date: Sun, 17 Apr 2022 18:13:40 -0700 Subject: [PATCH 1/2] update decryption alg --- ani-cli | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ani-cli b/ani-cli index 58f041e..573bbb9 100755 --- a/ani-cli +++ b/ani-cli @@ -106,13 +106,12 @@ decrypt_link() { lg "BEGIN: decrypt_link()" > /dev/stderr ajax_url="$BASE_URL/encrypt-ajax.php" id=$(printf "%s" "$1" | sed -nE 's/.*id=(.*)&title.*/\1/p') - resp=$(curl -s "$1") - secret_key=$(printf "%s" "$resp" | sed -nE 's/.*class="container-(.*)">/\1/p' | tr -d "\n" | od -A n -t x1 | tr -d " |\n") - iv=$(printf "%s" "$resp" | sed -nE 's/.*class="wrapper container-(.*)">/\1/p' | tr -d "\n" | od -A n -t x1 | tr -d " |\n") - second_key=$(printf "%s" "$resp" | sed -nE 's/.*class=".*videocontent-(.*)">/\1/p' | tr -d "\n" | od -A n -t x1 | tr -d " |\n") + iv=$(curl -s "$1" | sed -nE 's/.*class="wrapper container-(.*)">/\1/p' | tr -d "\n" | od -A n -t x1 | tr -d " |\n") + dec_id=$(printf "%s" "$id" | base64 -d | od -A n -t x1 | tr -d " |\n") + secret_key=$(printf "%s%s" "$dec_id" "$iv" | cut -c-32 | tr -d "\n" | od -A n -t x1 | tr -d " |\n") ajax=$(printf '%s' "$id" | openssl enc -e -aes256 -K "$secret_key" -iv "$iv" | base64) data=$(curl -s -H "X-Requested-With:XMLHttpRequest" "$ajax_url" -d "id=$ajax" -d "alias=$id" | sed -e 's/{"data":"//' -e 's/"}/\n/' -e 's/\\//g') - printf '%s' "$data" | base64 -d | openssl enc -d -aes256 -K "$second_key" -iv "$iv" | sed -e 's/\].*/\]/' -e 's/\\//g' | + printf '%s' "$data" | base64 -d | openssl enc -d -aes256 -K "$secret_key" -iv "$iv" | sed -e 's/\].*/\]/' -e 's/\\//g' | grep -Eo 'https:\/\/[-a-zA-Z0-9@:%._\+~#=][a-zA-Z0-9][-a-zA-Z0-9@:%_\+.~#?&\/\/=]*' lg "END: decrypt_link()" > /dev/stderr } From ae0c19b5f23157464c677cdb9a0df80168d1e335 Mon Sep 17 00:00:00 2001 From: ksyasuda Date: Sun, 17 Apr 2022 18:43:14 -0700 Subject: [PATCH 2/2] add m3u8 quality parsing and fix mp4 quality parsing --- ani-cli | 71 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/ani-cli b/ani-cli index 573bbb9..6dd7575 100755 --- a/ani-cli +++ b/ani-cli @@ -2,6 +2,7 @@ BASE_URL="https://goload.pro" CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/aniwrapper" +URLFILE="${XDG_CONFIG_HOME:-$HOME/.config}/aniwrapper/ani-url" HISTORY_DB="$CFG_DIR/history.sqlite3" ROFI_CFG="$CFG_DIR/themes/aniwrapper.rasi" ROFI_THEME="aniwrapper.rasi" @@ -97,7 +98,7 @@ download() { aria2c --summary-interval=0 -x 16 -s 16 --referer="$1" "$2" --dir="$5" -o "${4}" --download-result=hide ;; *) - ffmpeg -loglevel error -stats -referer "$1" -i "$2" -c copy "$5/${4}" + ffmpeg -loglevel error -stats -referer "$1" -i "$2" -map "0:p:$((idx - 1))?" -c copy "$5/${4}" ;; esac } @@ -117,28 +118,64 @@ decrypt_link() { } # chooses the link for the set quality -get_video_quality() { +get_video_link() { dpage_url=$1 video_links=$(decrypt_link "$dpage_url") + lg "Quality: $quality" > /dev/stderr + if printf '%s' "$video_links" | grep -q "mp4"; then + video_url=$(get_video_quality_mp4 "$video_links") + idx=1 + else + video_url="$video_links" + get_video_quality_m3u8 + fi +} + +get_video_quality_mp4() { + lg "BEGIN: get_video_quality_mp4()" > /dev/stderr case $quality in best) - video_link=$(printf '%s' "$video_links" | head -n 4 | tail -n 1) + video_url=$(printf '%s' "$1" | head -n 4 | tail -n 1) ;; worst) - video_link=$(printf '%s' "$video_links" | head -n 1) + video_url=$(printf '%s' "$1" | head -n 1) ;; *) - video_link=$(printf '%s' "$video_links" | grep -i "${quality}" | head -n 1) - if [ -z "$video_link" ]; then + video_url=$(printf '%s' "$1" | grep -i "${quality}" | head -n 1) + if [ -z "$video_url" ]; then err "Current video quality is not available (defaulting to best quality)" quality=best - video_link=$(printf '%s' "$video_links" | head -n 4 | tail -n 1) + video_url=$(printf '%s' "$1" | head -n 4 | tail -n 1) fi ;; esac - printf '%s' "$video_link" + lg "END: get_video_quality_mp4()" > /dev/stderr + printf '%s' "$video_url" +} + +get_video_quality_m3u8() { + lg "BEGIN: get_video_quality_m3u8()" > /dev/stderr + case $quality in + worst | 360p) + idx=2 + ;; + 480p) + idx=3 + ;; + 720p) + idx=4 + ;; + 1080p | best) + idx=5 + ;; + *) + idx=5 + ;; + esac + lg "END: get_video_quality_m3u8() -> idx = $idx" > /dev/stderr + printf '%s' "$video_url" | grep -qE "gogocdn.*m3u.*" && idx=$((idx - 1)) } # sets the video quality @@ -543,12 +580,17 @@ extended_search() { sed -n -E 's_^[[:space:]]* "$URLFILE" +} + check_episode() { data=$(curl -s "$BASE_URL/videos/$1") - if [ "$data" != "404" ]; then - del=$(printf "%s" "$data" | grep -n "Latest Episodes" | cut -d ":" -f1) - printf "%s" "$data" | sed "$del,$ d" | sed -nE "s_^[[:space:]]*_\1_p" - fi + del=$(printf "%s" "$data" | grep -n "Latest Episodes" | cut -d ":" -f1) + [ -n "$del" ] && printf "%s" "$data" | sed "$del,$ d" | sed -nE "s_^[[:space:]]*_\1_p" } search_eps() { @@ -680,7 +722,7 @@ open_episode() { if [[ -z "$dpage_link" ]]; then die "Could not get download page link" else - video_url=$(get_video_quality "$dpage_link") + get_video_link "$dpage_link" fi lg "Download link: $dpage_link" lg "Video url: $video_url" @@ -689,7 +731,7 @@ open_episode() { kill "$PID" > /dev/null 2>&1 case "$PLAYER_FN" in mpv) - nohup "$PLAYER_FN" --referrer="$dpage_link" "$video_url" --force-media-title="aniwrapper: $anime_id E$(printf "%03d" "$episode")" > /dev/null 2>&1 & + nohup "$PLAYER_FN" --vid="$idx" --referrer="$dpage_link" "$video_url" --force-media-title="aniwrapper: $anime_id E$(printf "%03d" "$episode")" > /dev/null 2>&1 & ;; vlc) nohup "$PLAYER_FN" --play-and-exit --http-referrer="$dpage_link" "$video_url" > /dev/null 2>&1 & @@ -997,3 +1039,4 @@ dep_ch "$PLAYER_FN" "curl" "sed" "grep" "sqlite3" "rofi" "git" "aria2c" "openssl parse_args "$@" shift $((OPTIND - 1)) main "$@" +updateurl &