mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-11-22 03:19:53 -08:00
better sync history functions
This commit is contained in:
parent
9662a28aa4
commit
b4afebe72c
24
ani-cli
24
ani-cli
@ -232,6 +232,7 @@ update_date() {
|
|||||||
WHERE anime_name = '$1' \
|
WHERE anime_name = '$1' \
|
||||||
AND episode_number = $2;"
|
AND episode_number = $2;"
|
||||||
fi
|
fi
|
||||||
|
wait # in case there's another insert/update still running in background?
|
||||||
run_stmt "$stmt"
|
run_stmt "$stmt"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +245,6 @@ insert_history() {
|
|||||||
res="$?"
|
res="$?"
|
||||||
if [[ $res -gt 0 ]]; then
|
if [[ $res -gt 0 ]]; then
|
||||||
logger "Match found... Updating row in history db..."
|
logger "Match found... Updating row in history db..."
|
||||||
wait # in case there's another insert/update still running in background?
|
|
||||||
update_date "$@"
|
update_date "$@"
|
||||||
res=$?
|
res=$?
|
||||||
else
|
else
|
||||||
@ -276,19 +276,19 @@ sync_search_history() {
|
|||||||
errs=0
|
errs=0
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
anime_name=$(awk -F '|' '{print $2}' <<< "$line")
|
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'")
|
res=$(sqlite3 -noheader "$HISTORY_DB" "SELECT COUNT(*) FROM search_history WHERE anime_name = '$anime_name'")
|
||||||
if [[ "$res" -eq 0 ]]; then
|
if [[ "$res" -eq 0 ]]; then
|
||||||
search_date=$(awk -F '|' '{print $3}' <<< "$line")
|
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
|
if ! sqlite3 "$HISTORY_DB" "INSERT INTO search_history(anime_name, search_date) VALUES('$anime_name', '$search_date')"; then
|
||||||
((++errs))
|
((++errs))
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
((++cnt))
|
((++cnt))
|
||||||
fi
|
fi
|
||||||
logger
|
# logger
|
||||||
done <<< "$(sqlite3 -list -noheader "$temp_db" "SELECT DISTINCT * FROM search_history")"
|
done < <(sqlite3 -list -noheader "$temp_db" "SELECT DISTINCT * FROM search_history")
|
||||||
logger "$cnt rows inserted into search_history table"
|
logger "$cnt rows inserted into search_history table"
|
||||||
logger "$errs errors on insert"
|
logger "$errs errors on insert"
|
||||||
}
|
}
|
||||||
@ -299,11 +299,11 @@ sync_watch_history() {
|
|||||||
while read -r line; do
|
while read -r line; do
|
||||||
anime_name="${line/ //}"
|
anime_name="${line/ //}"
|
||||||
# some spacing for log messages
|
# 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'")
|
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
|
# for each episode of $anime_name on the remote machine, check local
|
||||||
while read -r ep; do
|
while read -r ep; do
|
||||||
logger
|
# logger
|
||||||
episode_num=$(awk -F '|' '{print $1}' <<< "$ep")
|
episode_num=$(awk -F '|' '{print $1}' <<< "$ep")
|
||||||
watch_date=$(awk -F '|' '{print $NF}' <<< "$ep")
|
watch_date=$(awk -F '|' '{print $NF}' <<< "$ep")
|
||||||
if ! insert_history "$anime_name" "$episode_num" "$watch_date"; then
|
if ! insert_history "$anime_name" "$episode_num" "$watch_date"; then
|
||||||
@ -312,7 +312,7 @@ sync_watch_history() {
|
|||||||
fi
|
fi
|
||||||
((++cnt))
|
((++cnt))
|
||||||
done <<< "${episodes[@]}"
|
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 "$cnt rows inserted into watch_history table"
|
||||||
logger "$errs rows skipped on insert"
|
logger "$errs rows skipped on insert"
|
||||||
}
|
}
|
||||||
@ -398,7 +398,11 @@ find_media() {
|
|||||||
case "$selection" in
|
case "$selection" in
|
||||||
Back | ../)
|
Back | ../)
|
||||||
dotdotslash="${inp%/*}"
|
dotdotslash="${inp%/*}"
|
||||||
[ -z "$dotdotslash" ] && find_media "/" || find_media "$dotdotslash"
|
if [ -z "$dotdotslash" ]; then
|
||||||
|
find_media "/"
|
||||||
|
else
|
||||||
|
find_media "$dotdotslash"
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
Quit)
|
Quit)
|
||||||
return 1
|
return 1
|
||||||
@ -701,7 +705,7 @@ stream() {
|
|||||||
logger "Searched before: $searched"
|
logger "Searched before: $searched"
|
||||||
fi
|
fi
|
||||||
if [ "$searched" -eq 0 ]; then
|
if [ "$searched" -eq 0 ]; then
|
||||||
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"
|
||||||
logger "SEARCH RESULTS: $search_results"
|
logger "SEARCH RESULTS: $search_results"
|
||||||
if ! anime_selection "$search_results"; then
|
if ! anime_selection "$search_results"; then
|
||||||
|
@ -275,7 +275,7 @@ main() {
|
|||||||
;;
|
;;
|
||||||
5.)
|
5.)
|
||||||
logger "Sync history database"
|
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:")
|
username=$($roficmd "Enter the username of the remote user:")
|
||||||
[ -z "$username" ] && seppuku "No username provided... exiting"
|
[ -z "$username" ] && seppuku "No username provided... exiting"
|
||||||
host=$($roficmd "Enter the host for the remote machine (eg 192.168.1.99):")
|
host=$($roficmd "Enter the host for the remote machine (eg 192.168.1.99):")
|
||||||
|
Loading…
Reference in New Issue
Block a user