Skip to content

Commit

Permalink
fix: allanime url, curl and referers
Browse files Browse the repository at this point in the history
* refactor: switch to curl by @coolansx

* fix: mac wc -l skill issue

* refactor: add whitespace to external menu anime prompt

* fix: change allanime api

* fix: change allanime api

* refactor: whitespace for query

* fix: previous,next,replay bug (#1028)

* fix: add referer (#1004)

* docs: replace wget with curl

---------

Co-authored-by: chokerman <44473782+justchokingaround@users.noreply.github.com>
Co-authored-by: justchokingaround <ivanonarch@tutanota.com>
Co-authored-by: RaynardGerraldo <RaynardGerraldo@users.noreply.github.com>
  • Loading branch information
4 people authored Feb 16, 2023
1 parent 817657e commit 94e78d5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</p>

<h3 align="center">
A cli to browse and watch anime (alone AND with friends). This tool scrapes the site <a href="https://allanime.site/">allanime.</a>
A cli to browse and watch anime (alone AND with friends). This tool scrapes the site <a href="https://allanime.co/">allanime.</a>
</h3>

<h1 align="center">
Expand Down Expand Up @@ -71,11 +71,9 @@ Otherwise you're likely to see an error like the following: ` "/usr/bin/ani-cli:

#### Debian

Wget is replaced with wget2 to ensure compatibility with all Debian releases.

```sh
wget -qO- https://Wiener234.github.io/ani-cli-ppa/KEY.gpg | sudo tee /etc/apt/trusted.gpg.d/ani-cli.asc
wget -qO- https://Wiener234.github.io/ani-cli-ppa/ani-cli-debian.list | sudo tee /etc/apt/sources.list.d/ani-cli-debian.list
curl -s https://Wiener234.github.io/ani-cli-ppa/KEY.gpg | sudo tee /etc/apt/trusted.gpg.d/ani-cli.asc
curl -s https://Wiener234.github.io/ani-cli-ppa/ani-cli-debian.list | sudo tee /etc/apt/sources.list.d/ani-cli-debian.list
sudo apt update
sudo apt install ani-cli
```
Expand Down Expand Up @@ -142,7 +140,7 @@ cd .. && rm -rf ./ani-cli
*To install (with Homebrew) the dependencies required on Mac OS, you can run:*

```sh
brew install wget grep aria2 ffmpeg git fzf && \
brew install curl grep aria2 ffmpeg git fzf && \
brew install --cask iina
```
*Why iina and not mpv? Drop-in replacement for mpv for MacOS. Integrates well with OSX UI. Excellent support for M1. Open Source.*
Expand Down Expand Up @@ -214,7 +212,7 @@ git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install

mkdir ~/.aria2c
wget -O ~/.aria2c/aria2-1.36.0.tar.bz2 https://github.com/q3aql/aria2-static-builds/releases/download/v1.36.0/aria2-1.36.0-linux-gnu-64bit-build1.tar.bz2
curl -o ~/.aria2c/aria2-1.36.0.tar.bz2 https://github.com/q3aql/aria2-static-builds/releases/download/v1.36.0/aria2-1.36.0-linux-gnu-64bit-build1.tar.bz2
tar xvf ~/.aria2c/aria2-1.36.0.tar.bz2 -C ~/.aria2c/
cp ~/.aria2c/aria2-1.36.0-linux-gnu-64bit-build1/aria2c ~/.local/bin/
chmod +x ~/.local/bin/aria2c
Expand Down Expand Up @@ -253,7 +251,7 @@ press enter("A" button on Steam Deck) on questions

```sh
mkdir ~/.aria2c
wget -O ~/.aria2c/aria2-1.36.0.tar.bz2 https://github.com/q3aql/aria2-static-builds/releases/download/v1.36.0/aria2-1.36.0-linux-gnu-64bit-build1.tar.bz2
curl -o ~/.aria2c/aria2-1.36.0.tar.bz2 https://github.com/q3aql/aria2-static-builds/releases/download/v1.36.0/aria2-1.36.0-linux-gnu-64bit-build1.tar.bz2
tar xvf ~/.aria2c/aria2-1.36.0.tar.bz2 -C ~/.aria2c/
cp ~/.aria2c/aria2-1.36.0-linux-gnu-64bit-build1/aria2c ~/.local/bin/
chmod +x ~/.local/bin/aria2c
Expand Down Expand Up @@ -349,7 +347,7 @@ flatpak uninstall io.mpv.Mpv

- grep
- sed
- wget (v.1.21.3)
- curl
- mpv - Video Player
- iina - mpv replacement for MacOS
- aria2c - Download manager
Expand All @@ -365,7 +363,6 @@ flatpak uninstall io.mpv.Mpv
* [dra-cla](https://github.com/CoolnsX/dra-cla): ani-cli equivalent for korean dramas (Shell)
* [kaa.si-cli](https://github.com/Soviena/kaa.si-cli): Stream anime from kaa.si and sync with anilist (Python)
* [lobster](https://github.com/justchokingaround/lobster): Life action movies and series fom the terminal (Shell)
* [manga-cli](https://github.com/7USTIN/manga-cli): Read manga in the cli (Shell)
* [mangal](https://github.com/metafates/mangal): Download & read manga from any source with anilist sync (Go)
* [mov-cli](https://github.com/mov-cli/mov-cli): Watch movies/shows in the cli (Python/Shell)
* [saikou](https://github.com/saikou-app/saikou): Best android app for anime/manga with anilist integration (Kotlin)
Expand Down
43 changes: 22 additions & 21 deletions ani-cli
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

version_number="4.0.9"
version_number="4.1.0"

# UI

Expand All @@ -17,7 +17,7 @@ launcher() {
nth() {
stdin=$(cat -)
[ -z "$stdin" ] && return 1
line_count="$(printf "%s\n" "$stdin" | wc -l)"
line_count="$(printf "%s\n" "$stdin" | wc -l | tr -d "[:space:]")"
[ "$line_count" -eq 1 ] && printf "%s" "$stdin" | cut -f2,3 && return 0
prompt="$1"
multi_flag=""
Expand Down Expand Up @@ -77,7 +77,7 @@ version_info() {
}

update_script() {
update="$(wget -q -O - -U "$agent" "https://raw.githubusercontent.com/pystardust/ani-cli/master/ani-cli")" || die "Connection error"
update="$(curl -s --cipher "AES256-SHA256" --tls-max "1.2" -A "$agent" "https://raw.githubusercontent.com/pystardust/ani-cli/master/ani-cli")" || die "Connection error"
update="$(printf '%s\n' "$update" | diff -u "$0" -)"
if [ -z "$update" ]; then
printf "Script is up to date :)\n"
Expand All @@ -102,10 +102,10 @@ dep_ch() {

# extract the video links from reponse of embed urls, extract mp4 links form m3u8 lists
get_links() {
episode_link="$(wget -q -O - "https://blog.allanime.pro/apivtwo/clock.json?id=$*" -U "$agent" | sed 's|},{|\n|g' | sed -nE 's|.*link":"([^"]*)".*"resolutionStr":"([^"]*)".*|\2 >\1|p;s|.*hls","url":"([^"]*)".*"hardsub_lang":"en-US".*|\1|p')"
episode_link="$(curl -e "https://allanime.co" -s --cipher "AES256-SHA256" "https://allanimenews.com/apivtwo/clock.json?id=$*" -A "$agent" | sed 's|},{|\n|g' | sed -nE 's|.*link":"([^"]*)".*"resolutionStr":"([^"]*)".*|\2 >\1|p;s|.*hls","url":"([^"]*)".*"hardsub_lang":"en-US".*|\1|p')"
case "$episode_link" in
*crunchyroll*)
wget -q -O - "$episode_link" -U "$agent" | sed 's|^#.*x||g; s|,.*|p|g; /^#/d; $!N; s|\n| >|' | sort -nr
curl -e "https://allanime.co" -s --cipher "AES256-SHA256" --tls-max "1.2" "$episode_link" -A "$agent" | sed 's|^#.*x||g; s|,.*|p|g; /^#/d; $!N; s|\n| >|' | sort -nr
;;
*repackager.wixmp.com*)
extract_link=$(printf "%s" "$episode_link" | cut -d'>' -f2 | sed 's|repackager.wixmp.com/||g;s|\.urlset.*||g')
Expand All @@ -119,7 +119,7 @@ get_links() {
else
extract_link=$(printf "%s" "$episode_link" | head -1 | cut -d'>' -f2)
relative_link=$(printf "%s" "$extract_link" | sed 's|[^/]*$||')
wget -q -O - "$extract_link" -U "$agent" | sed 's|^#.*x||g; s|,.*|p|g; /^#/d; $!N; s|\n| >|' | sed "s|>|>${relative_link}|g" | sort -nr
curl -e "https://allanime.co/" -s --cipher "AES256-SHA256" --tls-max "1.2" "$extract_link" -A "$agent" | sed 's|^#.*x||g; s|,.*|p|g; /^#/d; $!N; s|\n| >|' | sed "s|>|>${relative_link}|g" | sort -nr
fi
;;
*) [ -n "$episode_link" ] && printf "%s\n" "$episode_link" ;;
Expand All @@ -136,9 +136,9 @@ provider_init() {
# generates links based on given provider
generate_link() {
case $1 in
1) provider_init 'wixmp' '/Default :/p' ;; # wixmp(default)(m3u8)(multi) -> (mp4)(multi)
1) provider_init 'wixmp' '/Default :/p' ;; # wixmp(default)(m3u8)(multi) -> (mp4)(multi)
2) provider_init 'pstatic' '/Default B :/p' ;; # pstatic(default backup)(mp4)(multi)
3) provider_init 'vrv' '/Ac :/p' ;; # vrv(crunchyroll)(m3u8)(multi)
3) provider_init 'vrv' '/Ac :/p' ;; # vrv(crunchyroll)(m3u8)(multi)
4) provider_init 'sharepoint' '/S-mp4 :/p' ;; # sharepoint(mp4)(single)
5) provider_init 'usercloud' '/Uv-mp4 :/p' ;; # usercloud(mp4)(single)
*) provider_init 'gogoanime' '/Luf-mp4 :/p' ;; # gogoanime(m3u8)(multi)
Expand All @@ -159,7 +159,7 @@ select_quality() {
# gets embed urls, collects direct links into provider files, selects one with desired quality into $episode
get_episode_url() {
# get the embed urls of the selected episode
resp=$(wget -q -O - "https://allanime.site/watch/$id/episode-$ep_no-$mode" -U "$agent" | tr '{}' '\n' | sed 's|\\u002F|\/|g;s|\\||g' | sed -nE 's|.*sourceUrl":".*clock\?id=([^"]*)".*sourceName":"([^"]*)".*|\2 :\1|p')
resp=$(curl -e "https://allanime.co" -s --cipher "AES256-SHA256" --tls-max "1.2" "https://api.allanime.co/allanimeapi?variables=%7B%22showId%22%3A%22$id%22%2C%22translationType%22%3A%22$mode%22%2C%22countryOrigin%22%3A%22ALL%22%2C%22episodeString%22%3A%22$ep_no%22%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%221f0a5d6c9ce6cd3127ee4efd304349345b0737fbf5ec33a60bbc3d18e3bb7c61%22%7D%7D" -A "$agent" | tr '{}' '\n' | sed 's|\\u002F|\/|g;s|\\||g' | sed -nE 's|.*sourceUrl":".*clock\?id=([^"]*)".*sourceName":"([^"]*)".*|\2 :\1|p')
# generate links into sequential files
provider=1
i=0
Expand All @@ -177,12 +177,12 @@ get_episode_url() {

# search the query and give results
search_anime() {
wget -q -O - "https://allanime.site/allanimeapi?variables=%7B%22search%22%3A%7B%22allowAdult%22%3Atrue%2C%22allowUnknown%22%3Atrue%2C%22query%22%3A%22$*%22%7D%2C%22limit%22%3A40%2C%22page%22%3A1%2C%22translationType%22%3A%22$mode%22%2C%22countryOrigin%22%3A%22ALL%22%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%229c7a8bc1e095a34f2972699e8105f7aaf9082c6e1ccd56eab99c2f1a971152c6%22%7D%7D" -U "$agent" | sed 's|Show|\n|g' | sed -nE "s|.*_id\":\"([^\"]*)\",\"name\":\"(.*)\",\"english.*\"$mode\":([1-9][^,]*).*|\1\t\2 (\3 episode)|p" | sed 's/\\//g;s/"//g'
curl -e "https://allanime.co" -s --cipher "AES256-SHA256" --tls-max "1.2" "https://api.allanime.co/allanimeapi?variables=%7B%22search%22%3A%7B%22allowAdult%22%3Atrue%2C%22allowUnknown%22%3Atrue%2C%22query%22%3A%22$*%22%7D%2C%22limit%22%3A40%2C%22page%22%3A1%2C%22translationType%22%3A%22$mode%22%2C%22countryOrigin%22%3A%22ALL%22%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%229c7a8bc1e095a34f2972699e8105f7aaf9082c6e1ccd56eab99c2f1a971152c6%22%7D%7D" -A "$agent" | sed 's|Show|\n|g' | sed -nE "s|.*_id\":\"([^\"]*)\",\"name\":\"(.*)\",\"english.*\"$mode\":([1-9][^,]*).*|\1\t\2 (\3 episode)|p" | sed 's/\\//g;s/"//g'
}

# get the episodes list of the selected anime
episodes_list() {
wget -q -O - "https://allanime.site/anime/$*" -U "$agent" | sed 's|\\||g' | sed -nE "s|.*$mode\":\[([0-9.\",]*)\].*|\1|p" | sed 's|,|\n|g; s|"||g' | sort -n -k 1
curl -e "https://allanime.co" -s "https://api.allanime.co/allanimeapi?variables=%7B%22_id%22%3A%22$*%22%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%22f73a8347df0e3e794f8955a18de6e85ac25dfc6b74af8ad613edf87bb446a854%22%7D%7D" -A "$agent" | sed 's|\\||g' | sed -nE "s|.*$mode\":\[([0-9.\",]*)\].*|\1|p" | sed 's|,|\n|g; s|"||g' | sort -n -k 1
}

# PLAYING
Expand Down Expand Up @@ -225,18 +225,18 @@ play_episode() {
catt) nohup catt cast "$episode" >/dev/null 2>&1 & ;;
*) nohup "$player_function" "$episode" >/dev/null 2>&1 & ;;
esac
update_history
replay="$episode"
unset episode
update_history
wait
}

play() {
start=$(printf "%s" "$ep_no" | grep -Eo "^[0-9]+(\.[0-9])?")
end=$(printf "%s" "$ep_no" | grep -Eo "[0-9]+(\.[0-9])?$")
[ -z "$end" ] || [ "$end" = "$start" ] && unset start end
line_count=$(printf "%s\n" "$ep_no" | wc -l)
if [ "$line_count" != 1 ] || [ -n "$start" ] ; then
line_count=$(printf "%s\n" "$ep_no" | wc -l | tr -d "[:space:]")
if [ "$line_count" != 1 ] || [ -n "$start" ]; then
[ -z "$start" ] && start=$(printf "%s\n" "$ep_no" | head -n1)
[ -z "$end" ] && end=$(printf "%s\n" "$ep_no" | tail -n1)
range=$(printf "%s\n" "$ep_list" | sed -nE "/^${start}\$/,/^${end}\$/p")
Expand All @@ -252,7 +252,6 @@ play() {
fi
}


# MAIN

# setup
Expand Down Expand Up @@ -304,7 +303,7 @@ while [ $# -gt 0 ]; do
-c | --continue) search=history ;;
-d | --download) player_function=download ;;
-D | --delete)
: > "$histfile"
: >"$histfile"
exit 0
;;
-V | --version) version_info ;;
Expand All @@ -321,7 +320,7 @@ while [ $# -gt 0 ]; do
shift
done
printf "\33[2K\r\033[1;34mChecking dependencies...\033[0m\n"
dep_ch "wget" "sed" "grep" "fzf" || true
dep_ch "curl" "sed" "grep" "fzf" || true
case "$player_function" in
debug) ;;
download) dep_ch "ffmpeg" "aria2c" ;;
Expand Down Expand Up @@ -355,7 +354,7 @@ history)
if [ "$use_external_menu" = "0" ]; then
printf "Search anime: " && read -r query
else
query=$(: | external_menu "" "Search anime:")
query=$(: | external_menu "" "Search anime: ")
fi
done
query=$(printf "%s" "$query" | sed "s| |%20|g")
Expand Down Expand Up @@ -384,9 +383,11 @@ while cmd=$(printf "next\nreplay\nprevious\nselect\nchange_quality\nquit" | nth
replay) episode="$replay";;
previous) ep_no=$(printf "%s" "$ep_list" | sed -n "/^${ep_no}$/{g;1!p;};h") 2>/dev/null ;;
select) ep_no=$(printf "%s" "$ep_list" | nth "Select episode: " "$multi_selection_flag") ;;
change_quality) episode=$(printf "%s" "$links" | sed -n '/^\([0-9]*p\)/p' | launcher)
quality=$(printf "%s" "$episode" | grep -oE "^[0-9]+")
episode=$(printf "%s" "$episode" | cut -d'>' -f2);;
change_quality)
episode=$(printf "%s" "$links" | sed -n '/^\([0-9]*p\)/p' | launcher)
quality=$(printf "%s" "$episode" | grep -oE "^[0-9]+")
episode=$(printf "%s" "$episode" | cut -d'>' -f2)
;;
*) exit 0 ;;
esac
[ -z "$ep_no" ] && die "Out of range"
Expand Down

0 comments on commit 94e78d5

Please sign in to comment.