better sync history functions

This commit is contained in:
ksyasuda 2022-01-11 22:01:05 -08:00
parent 9662a28aa4
commit b4afebe72c
2 changed files with 15 additions and 11 deletions

24
ani-cli
View File

@ -232,6 +232,7 @@ update_date() {
WHERE anime_name = '$1' \
AND episode_number = $2;"
fi
wait # in case there's another insert/update still running in background?
run_stmt "$stmt"
}
@ -244,7 +245,6 @@ insert_history() {
res="$?"
if [[ $res -gt 0 ]]; then
logger "Match found... Updating row in history db..."
wait # in case there's another insert/update still running in background?
update_date "$@"
res=$?
else
@ -276,19 +276,19 @@ sync_search_history() {
errs=0
while read -r line; do
anime_name=$(awk -F '|' '{print $2}' <<< "$line")
logger "Checking if $anime_name has been searched..."
# logger "Checking if $anime_name has been searched..."
res=$(sqlite3 -noheader "$HISTORY_DB" "SELECT COUNT(*) FROM search_history WHERE anime_name = '$anime_name'")
if [[ "$res" -eq 0 ]]; then
search_date=$(awk -F '|' '{print $3}' <<< "$line")
logger "Not found in db... Adding ($anime_name|$search_date) to search history..."
# logger "Not found in db... Adding ($anime_name|$search_date) to search history..."
if ! sqlite3 "$HISTORY_DB" "INSERT INTO search_history(anime_name, search_date) VALUES('$anime_name', '$search_date')"; then
((++errs))
continue
fi
((++cnt))
fi
logger
done <<< "$(sqlite3 -list -noheader "$temp_db" "SELECT DISTINCT * FROM search_history")"
# logger
done < <(sqlite3 -list -noheader "$temp_db" "SELECT DISTINCT * FROM search_history")
logger "$cnt rows inserted into search_history table"
logger "$errs errors on insert"
}
@ -299,11 +299,11 @@ sync_watch_history() {
while read -r line; do
anime_name="${line/ //}"
# some spacing for log messages
logger && logger "ANIME: $anime_name"
# logger && logger "ANIME: $anime_name"
episodes=$(sqlite3 -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
while read -r ep; do
logger
# logger
episode_num=$(awk -F '|' '{print $1}' <<< "$ep")
watch_date=$(awk -F '|' '{print $NF}' <<< "$ep")
if ! insert_history "$anime_name" "$episode_num" "$watch_date"; then
@ -312,7 +312,7 @@ sync_watch_history() {
fi
((++cnt))
done <<< "${episodes[@]}"
done <<< "$(sqlite3 -list -noheader "$temp_db" "SELECT DISTINCT anime_name FROM watch_history")"
done < <(sqlite3 -list -noheader "$temp_db" "SELECT DISTINCT anime_name FROM watch_history")
logger "$cnt rows inserted into watch_history table"
logger "$errs rows skipped on insert"
}
@ -398,7 +398,11 @@ find_media() {
case "$selection" in
Back | ../)
dotdotslash="${inp%/*}"
[ -z "$dotdotslash" ] && find_media "/" || find_media "$dotdotslash"
if [ -z "$dotdotslash" ]; then
find_media "/"
else
find_media "$dotdotslash"
fi
;;
Quit)
return 1
@ -701,7 +705,7 @@ stream() {
logger "Searched before: $searched"
fi
if [ "$searched" -eq 0 ]; then
search_results=$(search_anime $query)
search_results=$(search_anime "$query")
[ -z "$search_results" ] && die "No search results found"
logger "SEARCH RESULTS: $search_results"
if ! anime_selection "$search_results"; then

View File

@ -275,7 +275,7 @@ main() {
;;
5.)
logger "Sync history database"
roficmd="rofi -dpi "$DPI" -dmenu -config $CFG_FILE -l 0 -p"
roficmd="rofi -dpi $DPI -dmenu -config $CFG_FILE -l 0 -p"
username=$($roficmd "Enter the username of the remote user:")
[ -z "$username" ] && seppuku "No username provided... exiting"
host=$($roficmd "Enter the host for the remote machine (eg 192.168.1.99):")