Skip to content

Commit

Permalink
Hist patch (#782)
Browse files Browse the repository at this point in the history
* feat:new hist-transition script
  • Loading branch information
CoolnsX authored Jun 21, 2022
1 parent 0ac0f92 commit 7154cea
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 35 deletions.
10 changes: 5 additions & 5 deletions bin/ani-cli
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ al_episode_list() {

process_hist_entry () {
temp_anime_id=$(printf "%s" "$anime_id" | sed 's/\t[0-9]*.$//')
latest_ep=$(printf "%s" "$anime_id" | sed "s/$temp_anime_id\t//g")
current_ep=$(printf "%s" "$anime_id" | sed "s/$temp_anime_id\t//g")
episode_list "$temp_anime_id"
current_ep=$last_ep_number
if [ -n "$current_ep" ] && [ "$current_ep" -ge "$latest_ep" ]; then
printf "%s\n" "$temp_anime_id"
latest_ep=$last_ep_number
if [ -n "$latest_ep" ] && [ "$latest_ep" -ge "$current_ep" ]; then
printf "%s : %s / %s\n" "$temp_anime_id" "$current_ep" "$latest_ep"
fi
}

Expand Down Expand Up @@ -346,7 +346,7 @@ anime_selection () {
done
fi
# Select respective anime_id
selection_id="$(printf "%s" "$search_results" | sed -n "${choice}p")"
selection_id="$(printf "%s" "$search_results" | sed -n "${choice}p" | cut -d':' -f1 | tr -d ' ')"
progress "(Gogoanime) Searching Episodes.."
episode_list "$selection_id"
al_episode_list
Expand Down
49 changes: 19 additions & 30 deletions hist_transition.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

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

die () {
err "$*"
Expand All @@ -14,47 +14,36 @@ err () {
}

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"
# display an informational message
printf "\033[1;35m%s\033[0m\n" "$*"
}

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'
search=$(printf '%s' "$1" | tr '-' '+' )
curl -A 'uwu' -s -X POST "$base_url/api/search/v1" -d "q2=$search" |
sed -e 's_</li>_\n_g' -e 's/\\//g' | sed -nE 's_.*a href="/v1/([^"]*)".*_\1_p' | head -1
}

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
query=$(printf "%s" "$anime_id" | sed 's/-episode.*//')
history_ep_number=$(printf "%s" "$anime_id" | sed "s/${query}-episode-//g")
search_result=$(search_anime "$query")
if [ -z "$search_result" ]; then
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 0
fi
printf "%s\n" "$search_results" | head -n 1 | sed "s/[0-9]*.$/${history_ep_number}/" | sed 's/\t//' >> "${histfile}.new"
printf "\033[1;32mFound Match for %s >> %s\n" "$query" "$search_result"
printf "%s\t%s\n" "$search_result" "$history_ep_number" >> "${histfile}.new"
}

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

0 comments on commit 7154cea

Please sign in to comment.