clean up code and fix sync watch history bug

This commit is contained in:
ksyasuda 2022-01-03 17:00:01 -08:00
parent ff4ee0a5f8
commit 9d7af52ad0
3 changed files with 13 additions and 24 deletions

View File

@ -138,7 +138,7 @@ As of the update on **_2022-01-01_**, if selecting an anime from the search hist
### Dealing with conflicting search queries / rofi grabbing from search list ### Dealing with conflicting search queries / rofi grabbing from search list
I can write more about it later, but in this program, rofi is configured to search with case insensitivity and select the best match from the list if there are matches. This can make it difficult at times to write a search query that does not trigger a selection from the rofi menu In this program, rofi is configured to search with case insensitivity and select the best match from the list if there are matches. This can make it difficult at times to write a search query that does not trigger a selection from the rofi menu
<div align="center"> <div align="center">

29
ani-cli
View File

@ -48,21 +48,6 @@ log() {
[ "$VERBOSE" -eq 1 ] && printf "%s\n" "$*" >&2 [ "$VERBOSE" -eq 1 ] && printf "%s\n" "$*" >&2
} }
search_new() {
# get anime name along with id
curl -s "$BASE_URL" |
sed -n -E '
s_^[[:space:]]*<a href="/([^"/.]*)" title="([^"]*)".*_\1_p
' |
sed -n -E '
s_^[[:space:]]*([^"]*)-episode-[0-9]{1,100}*_\1_p
'
}
resolve_url() {
curl --silent --location --head --output /dev/null --write-out '%{url_effective}' -- $1
}
search_anime() { search_anime() {
# get anime name along with its id # get anime name along with its id
log "NUM ARGS: $#" log "NUM ARGS: $#"
@ -140,11 +125,16 @@ get_links() {
embedded_video_url=$(get_embedded_video_link "$anime_id" "$episode") embedded_video_url=$(get_embedded_video_link "$anime_id" "$episode")
episode_id=$(echo "$embedded_video_url" | grep -oE "id.+?&") episode_id=$(echo "$embedded_video_url" | grep -oE "id.+?&")
video_url="https://gogoplay1.com/download?${episode_id}" video_url="https://gogoplay1.com/download?${episode_id}"
log 'GET_LINKS() VARS:'
log "embedded_video_url: $embedded_video_url"
log "episode_id: $episode_id"
log "video_url: $video_url"
} }
get_video_quality() { get_video_quality() {
get_links get_links
video_quality=$(curl -s "$video_url" | grep -oE "(http|https):\/\/.*com\/cdn.*expiry=[0-9]*" | sort -V | sed 's/amp;//') video_quality=$(curl -s "$video_url" | grep -oE "(http|https):\/\/.*com\/cdn.*expiry=[0-9]*" | sort -V | sed 's/amp;//')
log "VIDEO QUALITY: $video_quality"
case $quality in case $quality in
best) best)
play_link=$(echo "$video_quality" | sort -V | tail -n 1) play_link=$(echo "$video_quality" | sort -V | tail -n 1)
@ -281,9 +271,10 @@ sync_watch_history() {
# anime_name=$(awk -F '|' '{print $2}' <<<"$line") # anime_name=$(awk -F '|' '{print $2}' <<<"$line")
anime_name="${line/ //}" anime_name="${line/ //}"
log "ANIME: $anime_name" log "ANIME: $anime_name"
episodes=$(sqlite3 -noheader "$temp_db" "SELECT episode_number, watch_date FROM watch_history WHERE anime_name = '$anime_name'") episodes=$(sqlite3 -line -list -noheader "$temp_db" "SELECT episode_number, watch_date FROM watch_history WHERE anime_name = '$anime_name'")
# for each episode of $anime_name on the remote machine, check local # for each episode of $anime_name on the remote machine, check local
while read -r ep; do while read -r ep; do
log "ROW: $ep"
episode_num=$(awk -F '|' '{print $1}' <<< "$ep") episode_num=$(awk -F '|' '{print $1}' <<< "$ep")
check_db "$anime_name" "$episode_num" check_db "$anime_name" "$episode_num"
num=$? num=$?
@ -292,7 +283,7 @@ sync_watch_history() {
log "$anime_name - E$episode_num NOT IN DB" log "$anime_name - E$episode_num NOT IN DB"
watch_date=$(awk -F '|' '{print $NF}' <<< "$ep") watch_date=$(awk -F '|' '{print $NF}' <<< "$ep")
log "Adding ($anime_name|$episode_num|$watch_date) to watch history..." log "Adding ($anime_name|$episode_num|$watch_date) to watch history..."
if ! sqlite3 "$HISTORY_DB" "INSERT INTO watch_history(anime_name, episode_number, watch_date) VALUES('$anime_name', '$episode_num', '$watch_date')"; then if ! sqlite3 -noheader "$HISTORY_DB" "INSERT INTO watch_history(anime_name, episode_number, watch_date) VALUES('$anime_name', '$episode_num', '$watch_date')"; then
err "Error inserting row $ep" err "Error inserting row $ep"
fi fi
((++cnt)) ((++cnt))
@ -533,6 +524,7 @@ open_episode() {
fi fi
get_video_quality get_video_quality
log "Play link: $play_link"
status_code=$(curl -s -I "$play_link" | head -n 1 | cut -d ' ' -f2) status_code=$(curl -s -I "$play_link" | head -n 1 | cut -d ' ' -f2)
log "Status code: $status_code" log "Status code: $status_code"
@ -619,9 +611,6 @@ quality=best
is_rofi=1 is_rofi=1
is_download=0 is_download=0
download_dir="." download_dir="."
is_playlist=0
playlist_remove=0
playlist_add=0
half_ep=0 half_ep=0
while getopts 'hd:Hsvq:c' OPT; do while getopts 'hd:Hsvq:c' OPT; do
case "$OPT" in case "$OPT" in

View File

@ -8,7 +8,6 @@ set -Eeo pipefail
CMD="/usr/bin/ani-cli" CMD="/usr/bin/ani-cli"
DEFAULT_DOWNLOAD="$HOME/Videos/sauce" DEFAULT_DOWNLOAD="$HOME/Videos/sauce"
CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/aniwrapper" CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/aniwrapper"
DEFAULT_PLAYLIST="$CFG_DIR/playlists/playlist.txt"
CFG_FILE="aniwrapper.rasi" CFG_FILE="aniwrapper.rasi"
QUALITIES="1. best (default)|2. 1080p|3. 720p|4. 480p|5. 360p|6. worst" QUALITIES="1. best (default)|2. 1080p|3. 720p|4. 480p|5. 360p|6. worst"
QUALITY="best" QUALITY="best"
@ -66,8 +65,8 @@ log() {
fi fi
} }
# opens the passed in file with $PLAYER_CMD
play_file() { play_file() {
# opens the passed in file with $PLAYER_CMD
log "Checking if file is playable" log "Checking if file is playable"
if [[ "$1" =~ (\.mp4|\.mkv|\.ts)$ ]]; then if [[ "$1" =~ (\.mp4|\.mkv|\.ts)$ ]]; then
log "File is playable..." log "File is playable..."
@ -92,8 +91,8 @@ check_path() {
fi fi
} }
# recursive function for finding path to video file given a starting directory
find_videos() { find_videos() {
# recursive function for finding path to video file given a starting directory
inp="$1" inp="$1"
if [ -f "$inp" ]; then if [ -f "$inp" ]; then
echo "$inp" echo "$inp"
@ -150,6 +149,7 @@ elif [[ "$IS_ROFI" -eq 0 ]] && [[ "$IS_DOWNLOAD" -eq 1 ]]; then
printf "%s" "Enter download dir: " printf "%s" "Enter download dir: "
read -r dl_dir read -r dl_dir
log "Download dir: $dl_dir" log "Download dir: $dl_dir"
[ -d "$dl_dir" ] && mkdir -p "$dl_dir" || dir "Error creating directory: $dl_dir"
run "-cd $dl_dir" run "-cd $dl_dir"
exit $? exit $?
fi fi