Skip to content

Commit

Permalink
feat: transitionary tool for updating history file (#614)
Browse files Browse the repository at this point in the history
* Feature: tool for updating history file
(90% of time it works every time)

* Fix: handling empty histfiles

* Docs: added documentations for updating
  • Loading branch information
Derisis13 authored Apr 3, 2022
1 parent ce32a74 commit 590b112
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Latest stable version: 2.0.0
https://user-images.githubusercontent.com/44473782/160729779-41fe207c-b5aa-4fed-87db-313c83caf6bb.mp4

## Table of Contents
- [Fixing errors](#Fixing errors)
- [Install](#Installation)
- [Arch](#Arch)
- [Linux](#Linux)
Expand All @@ -42,6 +43,15 @@ https://user-images.githubusercontent.com/44473782/160729779-41fe207c-b5aa-4fed-
- [Contribution Guidelines](./CONTRIBUTING.md)
- [Disclaimer](./disclaimer.md)

### Fixing errors
if you encounter "Video url not found" or any breaking issue, then make sure youu are on latest version by typing
`sudo ani-cli -U` to update on linux, mac and android. On windows, run gitbash as administrator then there type `ani-cli -U`.
If after this the issue persists then open an issue.
<br>
If you see sed warnings or your history entries have disappeared after updating, then update your history file with the history
transition script (history_transition.sh). Download it: `git clone https://github.com/pystardust/ani-cli` then run: `./ani-cli/hist-transition.sh`
It doesn't work for all anime, but the ones it can't find will print out alongside their episode numbers. In the end clean up: `rm -rf ./ani-cli`

## Install

### Arch
Expand Down
60 changes: 60 additions & 0 deletions hist_transition.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh

histfile="${XDG_CACHE_HOME:-$HOME/.cache}/ani-hsts"
base_url="https://gogoplay4.com"

die () {
err "$*"
exit 1
}

# display an error message to stderr (in red)
err () {
printf "\033[1;31m%s\033[0m\n" "$*" >&2
}

inf () {
# display an informational message (first argument in green, second in magenta)
printf "\033[1;32m%s \033[1;35m%s\033[0m\n" "$1" "$2"
}

search_anime () {
search=$(printf '%s' "$1" | tr ' ' '-' )
curl -s "$base_url/search.html" -G -d "keyword=$search" |
sed -nE 's_^[[:space:]]*<a href="/videos/([^"]*)">_\1_p'
}

extended_search () {
indexing_url=$(curl -s -L -o /dev/null -w "%{url_effective}\n" https://gogoanime.cm)
search=$(printf '%s' "$1" | tr ' ' '-' )
curl -s "$indexing_url//search.html" -G -d "keyword=$search" |
sed -n -E 's_^[[:space:]]*<a href="/category/([^"]*)" title="([^"]*)".*_\1_p'
}

update_entry () {
query=$(printf "%s" "$anime_id" | sed 's/[0-9]*.$//' | sed 's/\t//')
history_ep_number=$(printf "%s" "$anime_id" | sed "s/${query}\t//g")
search_results=$(search_anime "$query")
if [ -z "$search_results" ]; then
extended_search_results=$(extended_search "$query")
if [ -n "$extended_search_results" ]; then
extended_search_results=$(printf '%s' "$extended_search_results" | head -n 1)
search_results=$(search_anime "$extended_search_results")
else
err "Can't find ${query}, you'll have to add this to your history manually (by playing it). You have episode ${history_ep_number} coming up."
return
fi
fi
printf "%s\n" "$search_results" | head -n 1 | sed "s/[0-9]*.$/${history_ep_number}/" | sed 's/\t//' >> "${histfile}.new"
}

inf "Transferring history..."
search_results=$(cat "$histfile")
[ -z "$search_results" ] && die "History is empty"
while read -r anime_id; do
update_entry &
done <<-EOF
$search_results
EOF
wait
mv "${histfile}.new" "$histfile"

0 comments on commit 590b112

Please sign in to comment.