scripts/anime_list.sh
30 lines · 1956 bytes · executable
1search_anime() {
2 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 } }}"
3
4 curl -e "$allanime_refr" -s -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|\
5|g' | sed -nE "s|.*_id\":\"([^\"]*)\",\"name\":\"([^\"]*)\".*${mode}\":([1-9][^,]*).*|\1 \2 (\3 episodes)NEWLINEFROMHERE|p"
6}
7
8agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/121.0"
9allanime_refr="https://allanime.to"
10allanime_base="allanime.day"
11allanime_api="https://api.${allanime_base}"
12mode="${ANI_CLI_MODE:-sub}"
13download_dir="${ANI_CLI_DOWNLOAD_DIR:-.}"
14quality="${ANI_CLI_QUALITY:-best}"
15case "$(uname -a)" in
16 *Darwin*) player_function="${ANI_CLI_PLAYER:-iina}" ;; # mac OS
17 *ndroid*) player_function="${ANI_CLI_PLAYER:-android_mpv}" ;; # Android OS (termux)
18 *steamdeck*) player_function="${ANI_CLI_PLAYER:-flatpak_mpv}" ;; # steamdeck OS
19 *MINGW* | *WSL2*) player_function="${ANI_CLI_PLAYER:-mpv.exe}" ;; # Windows OS
20 *ish*) player_function="${ANI_CLI_PLAYER:-iSH}" ;; # iOS (iSH)
21 *) player_function="${ANI_CLI_PLAYER:-mpv}" ;; # Linux OS
22esac
23
24# Read the entire file content into a variable
25query=$(cat ./scripts/tmp/query) # This is a shorthand for cat "$filename"
26
27# query="one piece"
28anime_list=$(search_anime "$query")
29
30echo $anime_list > ./scripts/tmp/anime_list