Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions ani-cli
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

version_number="5.2.0"
version_number="5.2.1"

# UI

Expand Down Expand Up @@ -237,9 +237,21 @@ animekai_m3u8() {
# the stream host wants the embed site as referer, and the embed url carries the mal id for ani-skip
refr="$(printf "%s" "$_embed" | sed -E 's|^(https?://[^/]*).*|\1/|')"
mal_id="$(printf "%s" "$_embed" | sed -nE 's|.*/mal/([0-9]+)/.*|\1|p')"
# the embed page only loads with a referer, and its sources endpoint only answers ajax requests
_id="$(animekai_curl "$_embed" -e "$base_api/" | sed -nE 's|.*data-id="([0-9]+)".*|\1|p' | head -n 1)"
[ -z "$_id" ] && die "No player id on the embed page: $_embed"
# the embed page only loads with a referer
_page="$(animekai_curl "$_embed" -e "$base_api/")"
_id="$(printf "%s" "$_page" | sed -nE 's|.*data-id="([0-9]+)".*|\1|p' | head -n 1)"
if [ -z "$_id" ]; then
# an embed without a player id (my.1anime.site) plays one mp4 straight from its source tag: no playlist, no subtitle track
_direct="$(printf "%s" "$_page" | sed -nE 's|.*<source src="([^"]*)".*|\1|p' | head -n 1)"
[ -z "$_direct" ] && die "No player id and no video source on the embed page: $_embed"
# its url carries no mal id either, the watch page links to the anime's MAL entry
#shellcheck disable=SC2059
[ "$skip_intro" = 1 ] && mal_id="$(animekai_curl "$(printf "$episodes_api" "$anime_id")" | sed -nE 's|.*myanimelist\.net/anime/([0-9]+).*|\1|p' | head -n 1)"
links="9999>$_direct"
sub_link=""
return 0
fi
# the sources endpoint only answers ajax requests
_json="$(animekai_curl "${refr}stream/getSources?id=${_id}" -H "X-Requested-With: XMLHttpRequest" | sed 's|\\/|/|g')"
_blob="$(printf "%s" "$_json" | sed -nE 's|.*"enc":"([^"]*)".*|\1|p')"
[ -z "$_blob" ] && die "No encrypted playlist in the embed's sources: ${refr}stream/getSources?id=${_id}"
Expand Down Expand Up @@ -345,8 +357,14 @@ download() {
_name="$(printf "%s" "$2" | tr '<>:"/\\|?*' '_')"
[ -n "$sub_link" ] && $curl_exe -sL -A "$agent" -e "$refr" --max-time 10 $cipher_flag "$sub_link" -o "$download_dir/$_name.vtt"
command -v "yt-dlp" >/dev/null && yt-dlp --referer "$refr" "$1" --no-skip-unavailable-fragments --fragment-retries infinite -N 16 -o "$download_dir/$_name.mp4" $3 && return 0

# ffmpeg skips the segments the stream host refuses when pulled at full speed, 10 times playback speed stays under its limit
ffmpeg -extension_picky 0 -referer "$refr" -readrate 10 -loglevel error -stats -i "$1" -c copy "$download_dir/$_name.mp4" $3
case "$1" in
*.m3u8*) _picky="-extension_picky 0" ;;
*) _picky="" ;;
esac

ffmpeg $_picky -referer "$refr" -readrate 10 -loglevel error -stats -i "$1" -c copy "$download_dir/$_name.mp4" $3
}

# mpv-android takes no options from the intent, so they go through a file the user includes in mpv.conf
Expand Down
Loading