From 37f60ffb219f066254f63d1b291dcaf3c7043f2d Mon Sep 17 00:00:00 2001 From: ksyasuda Date: Sat, 1 Jan 2022 21:10:53 -0800 Subject: [PATCH] clean up code a bit and fix sync watch history --- ani-cli | 11 ++++++----- aniwrapper | 38 +++++++++++++------------------------- 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/ani-cli b/ani-cli index 5bb6ccd..7877adc 100755 --- a/ani-cli +++ b/ani-cli @@ -264,13 +264,14 @@ sync_watch_history() { episodes=$(sqlite3 -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 while read -r ep; do + # log "EP: $ep" episode_num=$(awk -F '|' '{print $1}' <<<"$ep") - # TODO: Fix inserting duplicate rows - run_stmt "SELECT COUNT(*) FROM watch_history WHERE anime_name = '$anime_name' AND episode_number = $episode_num" + # log "EPISODE NUMBER: $episode_num" + check_db "$anime_name" "$episode_num" num=$? - log "EP: $ep" + log "COUNT for $anime_name - episode $episode_num: $num" if [[ "$num" -eq 0 ]]; then - log "NOT IN DB" + log "$anime_name - E$episode_num NOT IN DB" watch_date=$(awk -F '|' '{print $NF}' <<<"$ep") 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 @@ -278,7 +279,7 @@ sync_watch_history() { fi ((++cnt)) else - log "Episode: $episode_num found in the db... skipping" + log "$anime_name - Episode: $episode_num found in the db... skipping" fi done <<<"${episodes[@]}" done <<<"$(sqlite3 -noheader "$temp_db" "SELECT DISTINCT anime_name FROM watch_history")" diff --git a/aniwrapper b/aniwrapper index 23c3e5e..c2ef801 100755 --- a/aniwrapper +++ b/aniwrapper @@ -319,29 +319,19 @@ case "$selection" in # --------------------------------------------------------------------------- # play # --------------------------------------------------------------------------- - msg="Enter path to the videos directory or leave blank to go with the default: $HOME/Videos/sauce/" - span="$msg" - play_dir=$(rofi -dmenu -config "$CFG_DIR/$CFG_FILE" \ - -l 1 -mesg "$span" -p "Enter path to play dir:") - [ -z "$play_dir" ] && play_dir="$DEFAULT_DOWNLOAD" - log "PLAY DIR: $play_dir" - [ ! -d "$play_dir" ] && seppuku "$play_dir does not exist" - video_path=$(find_videos "$play_dir") - log "VIDEO PATH: $video_path" - if [ -z "$video_path" ]; then - seppuku "Something went wrong getting path" - fi - play_file "$video_path" - # selected_dir="$play_dir/$selection" - # [ ! -d "$selected_dir" ] && seppuku "$selected_dir does not exist" - # log "Selection is a directory, searching one level down" - # selection=$(rofi -dmenu -config "$CFG_DIR/$CFG_FILE" \ - # -l 12 -i -p "Enter selection" <<< $(ls "$selected_dir")) - # if [ -f "$selected_dir/$selection" ]; then - # play_file "$selected_dir/$selection" - # exit 0 - # fi - # seppuku "Selection not a file. exiting" + msg="Enter path to the videos directory or leave blank to go with the default: $HOME/Videos/sauce/" + span="$msg" + play_dir=$(rofi -dmenu -config "$CFG_DIR/$CFG_FILE" \ + -l 1 -mesg "$span" -p "Enter path to play dir:") + [ -z "$play_dir" ] && play_dir="$DEFAULT_DOWNLOAD" + log "PLAY DIR: $play_dir" + [ ! -d "$play_dir" ] && seppuku "$play_dir does not exist" + video_path=$(find_videos "$play_dir") + log "VIDEO PATH: $video_path" + if [ -z "$video_path" ]; then + seppuku "Something went wrong getting path" + fi + play_file "$video_path" ;; 5.) log "Sync history database" @@ -367,9 +357,7 @@ case "$selection" in if [[ -z "$keypath" ]]; then printf "%s\n%s\n%d\n%s\n" "$username" "$host" "$port" "" | run -s - # printf "%s\n%s\n%d\n%s\n" "$username" "$host" "$port" "" | ani-cli -s else - # printf "%s\n%s\n%d\n%s\n" "$username" "$host" "$port" "$keypath" | ani-cli -s printf "%s\n%s\n%d\n%s\n" "$username" "$host" "$port" "$keypath" | run -s fi