#!/bin/sh decrypt_allanime() { printf "%s" "$-" | grep -q 'x' && set +x for hex in $(printf '%s' "$1" | sed 's/../&\n/g'); do dec=$(printf '%d' "0x$hex") xor=$((dec ^ 56)) oct=$(printf "%03o" "$xor") #shellcheck disable=SC2059 printf "\\$oct" done printf "%s" "$-" | grep -q 'x' || set -x } allanime_curl() { curl -e "https://allanime.to" -sL --cipher AES256-SHA256 -G "https://api.${domain}/api" -A "$agent" --data-urlencode "$1" --data-urlencode "$2" } domain="allanime.day" random_no=$(head /dev/urandom | tr -dc '3-7' | cut -c1) agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/11${random_no}.0.0.0 Safari/537.36" debug=$2 case $(uname -o) in *ndroid*) os="droid" download_dir="/sdcard" script_dir="$HOME/.shortcuts" ;; *) os="linux" download_dir="$HOME/Downloads" [ -t 1 ] || terminal="${TERMINAL:-foot} -e" script_dir="$HOME/repos_scripts" ;; esac # shellcheck source=./.functions . "$script_dir/.functions" trap "exit 0" INT HUP info_$os "Parsing $domain.. Please wait..." #shellcheck disable=SC2016 [ -z "$1" ] && url=$(allanime_curl 'query=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 lastEpisodeInfo __typename}}}' 'variables={"search":{"sortBy":"Recent","allowAdult":true,"allowUnknown":true},"limit":40,"page":1,"translationType":"sub","countryOrigin":"JP"}' | sed 's|Show|\n|g' | sed -nE 's|.*_id":"([^"]*)","name":"([^"]*)".*sub":\{"episodeString":"([^"]*)".*|\1\t\2 Episode \3|p' | menu_$os "Select Anime: " '--with-nth 2.. -m' | tr ':' ' ' | tr -s ' ') || url=$(printf "%s" "$1" | sed -nE 's|.*/bangumi/([^/]*)/([^/]*)/.*episode-([^-]*)-sub|\1\t\2 Episode \3|p') [ -z "$url" ] && error_$os "No anime selected" && exit 0 printf "%s\n" "$url" | while read -r id title; do ep_no=$(printf "%s" "$title" | sed 's/.*Episode //g') info_$os "Loading Episode $title.." [ -n "$debug" ] && printf "\n\033[1;36m title\033[0m : %s\n" "$title" #shellcheck disable=SC2016 data=$(allanime_curl "variables={\"showId\":\"$id\",\"translationType\":\"sub\",\"countryOrigin\":\"ALL\",\"episodeString\":\"$ep_no\"}" 'query=query ($showId: String!, $translationType: VaildTranslationTypeEnumType!, $episodeString: String!) { episode( showId: $showId translationType: $translationType episodeString: $episodeString ) { episodeString sourceUrls }}' | tr '{}' '\n' | sed 's|\\u002F|\/|g;s|\\||g' | sed -nE 's|.*sourceUrl":"--([^"]*)".*sourceName":"([^"]*)".*|\2 :\1|p') info_$os "Fetching Embed links" printf 'dropbox\tSak\nwetransfer\tKir\nsharepoint\tS-mp4\ngogoplay\tLuf-mp4\n' | while read -r provider_name provider_regex; do info_$os "Fetching $provider_name links" provider_id="$(decrypt_allanime "$(printf "%s" "$data" | sed -n "/$provider_regex :/p" | head -1 | cut -d':' -f2)" | sed "s/\/clock/\/clock\.json/")" [ -z "$provider_id" ] && continue provider_video=$(curl -s "https://${domain}${provider_id}" | sed 's|},{|\n|g' | sed -nE 's|.*link":"([^"]*)".*"resolutionStr":"([^"]*)".*|\1|p;s|.*hls","url":"([^"]*)".*"hardsub_lang":"en-US".*|\1|p' | head -1) [ -z "$provider_video" ] && continue [ -n "$debug" ] && printf "\033[1;32m %s\033[0m : %s\n" "$provider_name" "$provider_video" && continue info_$os "$provider_name links fetched.." choice=$(printf "stream\ndownload\ncast\nnext_mirror\nnext_anime" | menu_$os "??" '' "2") [ -z "$choice" ] && break case $choice in stream) info_$os "opening $title" "mpv" player_$os "$provider_video" "$title" break ;; cast) info_$os "casting $title" "podcast" catt cast "$provider_video" break ;; *mirror) continue ;; download) info_$os "Downloading $title" "downloader" case $provider_video in *m3u*) $terminal hls -ro "$download_dir/$title" "$provider_video" || error_$os "Downloading failed $title" ;; *) $terminal aria2c -U "$agent" --check-certificate=false -d "$download_dir" --summary-interval=0 -x 16 -s 16 --referer="https://$domain" "$provider_video" -o "$title.mp4" --download-result=hide || error_$os "Downloading failed $title" ;; esac info_$os "Episode Downloaded $title" ;; esac break done done