update gogoanime link to fix query

This commit is contained in:
ksyasuda 2021-11-29 13:08:41 -08:00
parent cc9f7e7a44
commit 3b762fc4e4

298
ani-cli
View File

@ -7,7 +7,7 @@ fi
VERBOSE=0 VERBOSE=0
BASE_URL="https://gogoanime.cm" BASE_URL="https://www1.gogoanime.cm/"
CFG_DIR="$XDG_CONFIG_HOME/aniwrapper" CFG_DIR="$XDG_CONFIG_HOME/aniwrapper"
ROFI_CFG="meh.rasi" ROFI_CFG="meh.rasi"
@ -287,8 +287,8 @@ anime_selection() {
while read -r anime_id; do while read -r anime_id; do
# alternating colors for menu # alternating colors for menu
# [ $((count % 2)) -eq 0 ] && # [ $((count % 2)) -eq 0 ] &&
# menu_format_string=$menu_format_string_c1 || # menu_format_string=$menu_format_string_c1 ||
# menu_format_string=$menu_format_string_c2 # menu_format_string=$menu_format_string_c2
menu+="$count. $anime_id\n" menu+="$count. $anime_id\n"
idx=$((count - 1)) idx=$((count - 1))
@ -445,17 +445,17 @@ open_episode() {
video_url=$(get_links "$dpage_url") video_url=$(get_links "$dpage_url")
case $video_url in case $video_url in
*streamtape*) *streamtape*)
# If direct download not available then scrape streamtape.com # If direct download not available then scrape streamtape.com
BROWSER=${BROWSER:-firefox} BROWSER=${BROWSER:-firefox}
printf "scraping streamtape.com\n" printf "scraping streamtape.com\n"
video_url=$(curl -s "$video_url" | sed -n -E ' video_url=$(curl -s "$video_url" | sed -n -E '
/^<script>document/{ /^<script>document/{
s/^[^"]*"([^"]*)" \+ '\''([^'\'']*).*/https:\1\2\&dl=1/p s/^[^"]*"([^"]*)" \+ '\''([^'\'']*).*/https:\1\2\&dl=1/p
q q
} }
') ')
;; ;;
esac esac
if [ "$is_download" -eq 0 ]; then if [ "$is_download" -eq 0 ]; then
@ -496,47 +496,47 @@ playlist_remove=0
playlist_add=0 playlist_add=0
while getopts 'hd:Hpa:P:sv' OPT; do while getopts 'hd:Hpa:P:sv' OPT; do
case "$OPT" in case "$OPT" in
h) h)
help_text help_text
exit 0 exit 0
;; ;;
d) d)
is_download=1 is_download=1
download_dir="$OPTARG" download_dir="$OPTARG"
log "DOWNLOAD DIR: $download_dir" log "DOWNLOAD DIR: $download_dir"
;; ;;
H) H)
scrape=history scrape=history
;; ;;
p) p)
scrape=playlist scrape=playlist
is_playlist=1 is_playlist=1
;; ;;
a) a)
is_add=1 is_add=1
scrape=add scrape=add
playlist_file="${OPTARG/ //}" playlist_file="${OPTARG/ //}"
;; ;;
P) P)
is_playlist=1 is_playlist=1
# remove spaces from $OPTARG # remove spaces from $OPTARG
playlist_file="${OPTARG/ //}" playlist_file="${OPTARG/ //}"
[ -z "$playlist_file" ] && die "Enter in path to playlist" [ -z "$playlist_file" ] && die "Enter in path to playlist"
log "$playlist_file" log "$playlist_file"
$player_fn "$playlist_file" $player_fn "$playlist_file"
exit 0 exit 0
;; ;;
s) s)
scrape=sync scrape=sync
;; ;;
v) v)
VERBOSE=1 VERBOSE=1
;; ;;
*) *)
printf "%s\n" "Invalid option" printf "%s\n" "Invalid option"
exit 1 exit 1
;; ;;
esac esac
done done
shift $((OPTIND - 1)) shift $((OPTIND - 1))
@ -546,7 +546,36 @@ shift $((OPTIND - 1))
######## ########
case $scrape in case $scrape in
query) query)
get_search_query "$*"
search_results=$(search_anime "$query")
[ -z "$search_results" ] && die "No search results found"
if ! anime_selection "$search_results"; then
die "No anime selection found"
fi
episode_selection
;;
history)
stmt="SELECT DISTINCT anime_name FROM watch_history ORDER BY watch_date DESC"
search_results=$(printf "%s\n" "$stmt" | sqlite3 -noheader "$HISTORY_DB")
[ -z "$search_results" ] && die "History is empty"
if ! anime_selection "${search_results[@]}"; then
die "No anime selection found"
fi
log "SELECTION: $selection_id"
stmt="SELECT episode_number \
FROM watch_history \
WHERE anime_name = '$selection_id' \
ORDER BY watch_date DESC \
LIMIT 1"
ep_choice_start=$(run_stmt "$stmt")
log "Most recently watched episode: $ep_choice_start"
;;
playlist)
lines=$(wc -l <"$playlist_file")
log "Num lines in playlist: " "$lines"
if [[ "$lines" -eq 0 ]]; then
get_search_query "$*" get_search_query "$*"
search_results=$(search_anime "$query") search_results=$(search_anime "$query")
[ -z "$search_results" ] && die "No search results found" [ -z "$search_results" ] && die "No search results found"
@ -554,91 +583,62 @@ case $scrape in
die "No anime selection found" die "No anime selection found"
fi fi
episode_selection episode_selection
;; else
history) line=($(sed '1q;d' "$playlist_file"))
stmt="SELECT DISTINCT anime_name FROM watch_history ORDER BY watch_date DESC" if [[ "${#line[@]}" -ne 2 ]]; then
search_results=$(printf "%s\n" "$stmt" | sqlite3 -noheader "$HISTORY_DB") die "Something went wrong with the playlist file... exiting"
[ -z "$search_results" ] && die "History is empty"
if ! anime_selection "${search_results[@]}"; then
die "No anime selection found"
fi fi
log "SELECTION: $selection_id" selection_id="${line[0]}"
episodes=("$selection_id")
ep_choice_start="${line[1]}"
ep_choice_end=""
read -r last_ep_number <<-EOF
$(search_eps "$selection_id")
EOF
[ "$VERBOSE" -eq 1 ] && printf "Anime: %s Episode: %d\n" "$episodes" "$ep_choice_start"
[ "$VERBOSE" -eq 1 ] && printf "Episodes: %s\n" "${episodes[@]}"
fi
;;
add)
get_search_query "$*"
search_results=$(search_anime "$query")
[ -z "$search_results" ] && die "No search results found"
anime_selection "$search_results"
[ $? -ne 0 ] && die "No anime selection found"
episode_selection
;;
sync)
printf "%s" "Enter username for remote user: "
read -r username
printf "%s" "Enter host for remote user: "
read -r host
stmt="SELECT episode_number \ connection_str="$username@$host"
FROM watch_history \ printf "%s" "Enter port to connect to remote host with or leave blank for default (22): "
WHERE anime_name = '$selection_id' \ read -r port
ORDER BY watch_date DESC \ if [[ "${port/ //}" == "" ]]; then
LIMIT 1" PORT=22
ep_choice_start=$(run_stmt "$stmt") else
log "Most recently watched episode: $ep_choice_start" PORT="$port"
;; fi
playlist)
lines=$(wc -l < "$playlist_file" )
log "Num lines in playlist: " "$lines"
if [[ "$lines" -eq 0 ]]; then
get_search_query "$*"
search_results=$(search_anime "$query")
[ -z "$search_results" ] && die "No search results found"
if ! anime_selection "$search_results"; then
die "No anime selection found"
fi
episode_selection
else
line=($(sed '1q;d' "$playlist_file"))
if [[ "${#line[@]}" -ne 2 ]]; then
die "Something went wrong with the playlist file... exiting"
fi
selection_id="${line[0]}"
episodes=("$selection_id")
ep_choice_start="${line[1]}"
ep_choice_end=""
read -r last_ep_number <<-EOF
$(search_eps "$selection_id")
EOF
[ "$VERBOSE" -eq 1 ] && printf "Anime: %s Episode: %d\n" "$episodes" "$ep_choice_start"
[ "$VERBOSE" -eq 1 ] && printf "Episodes: %s\n" "${episodes[@]}"
fi
;;
add)
get_search_query "$*"
search_results=$(search_anime "$query")
[ -z "$search_results" ] && die "No search results found"
anime_selection "$search_results"
[ $? -ne 0 ] && die "No anime selection found"
episode_selection
;;
sync)
printf "%s" "Enter username for remote user: "
read -r username
printf "%s" "Enter host for remote user: "
read -r host
connection_str="$username@$host" printf "%s" "Enter path to private key (leave blank if unsure or not needed): "
printf "%s" "Enter port to connect to remote host with or leave blank for default (22): " read -r key_path
read -r port
if [[ "${port/ //}" == "" ]]; then
PORT=22
else
PORT="$port"
fi
printf "%s" "Enter path to private key (leave blank if unsure or not needed): " printf "%s\n" "Syncing database with: $connection_str on port $PORT"
read -r key_path temp_db="/tmp/aniwrapper_tmp_history.sqlite3"
printf "%s\n" "Syncing database with: $connection_str on port $PORT" if [[ -z "$key_path" ]]; then
temp_db="/tmp/aniwrapper_tmp_history.sqlite3" scp -P "$PORT" "$connection_str:$XDG_CONFIG_HOME/aniwrapper/history.sqlite3" "$temp_db"
else
if [[ -z "$key_path" ]]; then scp -P "$PORT" -i "$key_path" "$connection_str:$XDG_CONFIG_HOME/aniwrapper/history.sqlite3" "$temp_db"
scp -P "$PORT" "$connection_str:$XDG_CONFIG_HOME/aniwrapper/history.sqlite3" "$temp_db" fi
else if [[ "$?" -ne 0 ]]; then
scp -P "$PORT" -i "$key_path" "$connection_str:$XDG_CONFIG_HOME/aniwrapper/history.sqlite3" "$temp_db" die "Error getting database file from remote host"
fi fi
if [[ "$?" -ne 0 ]]; then sync_search_history && sync_watch_history
die "Error getting database file from remote host" exit 0
fi ;;
sync_search_history && sync_watch_history
exit 0
;;
esac esac
{ # checking input { # checking input
@ -688,29 +688,29 @@ while :; do
printf "$c_reset" printf "$c_reset"
case $choice in case $choice in
n) n)
episode=$((episode + 1)) episode=$((episode + 1))
;; ;;
p) p)
episode=$((episode - 1)) episode=$((episode - 1))
;; ;;
s) s)
printf "${c_blue}Choose episode $c_cyan[1-%d]$c_reset:$c_green " "$last_ep_number" printf "${c_blue}Choose episode $c_cyan[1-%d]$c_reset:$c_green " "$last_ep_number"
read -r episode read -r episode
printf "$c_reset" printf "$c_reset"
[ "$episode" -eq "$episode" ] 2>/dev/null || die "Invalid number entered" [ "$episode" -eq "$episode" ] 2>/dev/null || die "Invalid number entered"
;; ;;
r) ;; r) ;;
q) q)
break break
;; ;;
*) *)
die "invalid choice" die "invalid choice"
;; ;;
esac esac
open_episode "$selection_id" "$episode" "$download_dir" open_episode "$selection_id" "$episode" "$download_dir"
done done