clean up code a bit and fix sync watch history

This commit is contained in:
ksyasuda 2022-01-01 21:10:53 -08:00
parent 15ea028c4b
commit 37f60ffb21
2 changed files with 19 additions and 30 deletions

11
ani-cli
View File

@ -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'") 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 # for each episode of $anime_name on the remote machine, check local
while read -r ep; do while read -r ep; do
# log "EP: $ep"
episode_num=$(awk -F '|' '{print $1}' <<<"$ep") episode_num=$(awk -F '|' '{print $1}' <<<"$ep")
# TODO: Fix inserting duplicate rows # log "EPISODE NUMBER: $episode_num"
run_stmt "SELECT COUNT(*) FROM watch_history WHERE anime_name = '$anime_name' AND episode_number = $episode_num" check_db "$anime_name" "$episode_num"
num=$? num=$?
log "EP: $ep" log "COUNT for $anime_name - episode $episode_num: $num"
if [[ "$num" -eq 0 ]]; then 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") 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 "$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 fi
((++cnt)) ((++cnt))
else else
log "Episode: $episode_num found in the db... skipping" log "$anime_name - Episode: $episode_num found in the db... skipping"
fi fi
done <<<"${episodes[@]}" done <<<"${episodes[@]}"
done <<<"$(sqlite3 -noheader "$temp_db" "SELECT DISTINCT anime_name FROM watch_history")" done <<<"$(sqlite3 -noheader "$temp_db" "SELECT DISTINCT anime_name FROM watch_history")"

View File

@ -319,29 +319,19 @@ case "$selection" in
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# play # play
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
msg="Enter path to the videos directory or leave blank to go with the default: $HOME/Videos/sauce/" msg="Enter path to the videos directory or leave blank to go with the default: $HOME/Videos/sauce/"
span="<span foreground='peachpuff' style='italic' size='small' weight='light'>$msg</span>" span="<span foreground='peachpuff' style='italic' size='small' weight='light'>$msg</span>"
play_dir=$(rofi -dmenu -config "$CFG_DIR/$CFG_FILE" \ play_dir=$(rofi -dmenu -config "$CFG_DIR/$CFG_FILE" \
-l 1 -mesg "$span" -p "Enter path to play dir:") -l 1 -mesg "$span" -p "Enter path to play dir:")
[ -z "$play_dir" ] && play_dir="$DEFAULT_DOWNLOAD" [ -z "$play_dir" ] && play_dir="$DEFAULT_DOWNLOAD"
log "PLAY DIR: $play_dir" log "PLAY DIR: $play_dir"
[ ! -d "$play_dir" ] && seppuku "$play_dir does not exist" [ ! -d "$play_dir" ] && seppuku "$play_dir does not exist"
video_path=$(find_videos "$play_dir") video_path=$(find_videos "$play_dir")
log "VIDEO PATH: $video_path" log "VIDEO PATH: $video_path"
if [ -z "$video_path" ]; then if [ -z "$video_path" ]; then
seppuku "Something went wrong getting path" seppuku "Something went wrong getting path"
fi fi
play_file "$video_path" 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"
;; ;;
5.) 5.)
log "Sync history database" log "Sync history database"
@ -367,9 +357,7 @@ case "$selection" in
if [[ -z "$keypath" ]]; then 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" "" | run -s
# printf "%s\n%s\n%d\n%s\n" "$username" "$host" "$port" "" | ani-cli -s
else 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 printf "%s\n%s\n%d\n%s\n" "$username" "$host" "$port" "$keypath" | run -s
fi fi