From 4853dea3d533c1b02d018a286e1c774a69efd412 Mon Sep 17 00:00:00 2001 From: ksyasuda Date: Thu, 11 Nov 2021 14:13:11 -0800 Subject: [PATCH] add sync database option Added option to sync the history databases for the same user across devices on the same network (or the internet if that is set up on the machines) --- ani-cli | 310 +++++++++++++++++++++++++++++++++-------------------- aniwrapper | 216 ++++++++++++++++++++++++------------- db.sh | 64 ++++++++++- 3 files changed, 398 insertions(+), 192 deletions(-) diff --git a/ani-cli b/ani-cli index 9936699..0765499 100755 --- a/ani-cli +++ b/ani-cli @@ -118,6 +118,10 @@ run_stmt() { printf "%s\n" "$1" | sqlite3 -noheader "$HISTORY_DB" } +##################### +## Database Code ## +##################### + check_db() { # Return number of matches for anime/episode in db # echo "$1 $2" @@ -186,6 +190,47 @@ insert_history() { fi } +sync_search_history() { + cnt=0 + while read -r line; do + anime_name=$(awk -F '|' '{print $2}' <<<"$line") + res=$(sqlite3 -noheader "$HISTORY_DB" <<<"SELECT anime_name FROM search_history WHERE anime_name = '$anime_name'") + if [[ "${res/ //}" == "" ]]; then + printf "%s\n" "Adding $line to search history..." + search_date=$(awk -F '|' '{print $3}' <<<"$line") + sqlite3 "$HISTORY_DB" <<<"INSERT INTO search_history(anime_name, search_date) VALUES('$anime_name', '$search_date')" + if [[ "$?" -ne 0 ]]; then + err "Error inserting row $line" + fi + ((++cnt)) + fi + done <<<"$(sqlite3 -noheader "$temp_db" <<<"SELECT DISTINCT * FROM search_history")" + printf "%s\n" "Inserted $cnt rows into search_history table" +} + +sync_watch_history() { + cnt=0 + while read -r line; do + anime_name=$(awk -F '|' '{print $2}' <<<"$line") + res=$(sqlite3 -noheader "$HISTORY_DB" <<<"SELECT anime_name FROM watch_history WHERE anime_name = '$anime_name'") + if [[ "${res/ //}" == "" ]]; then + printf "%s\n" "Adding $line to watch history..." + episode_num=$(awk -F '|' '{print $3}' <<<"$line") + watch_date=$(awk -F '|' '{print $NF}' <<<"$line") + sqlite3 "$HISTORY_DB" <<<"INSERT INTO watch_history(anime_name, episode_number, watch_date) VALUES('$anime_name', '$episode_num', '$watch_date')" + if [[ "$?" -ne 0 ]]; then + err "Error inserting row $line" + fi + ((++cnt)) + fi + done <<<"$(sqlite3 -noheader "$temp_db" <<<"SELECT DISTINCT * FROM watch_history")" + printf "%s\n" "Inserted $cnt rows into watch_history table" +} + +##################### +## END of db code ## +##################### + # get query get_search_query() { # Query the anime to stream/download @@ -399,17 +444,17 @@ open_episode() { video_url=$(get_links "$dpage_url") case $video_url in - *streamtape*) - # If direct download not available then scrape streamtape.com - BROWSER=${BROWSER:-firefox} - printf "scraping streamtape.com\n" - video_url=$(curl -s "$video_url" | sed -n -E ' + *streamtape*) + # If direct download not available then scrape streamtape.com + BROWSER=${BROWSER:-firefox} + printf "scraping streamtape.com\n" + video_url=$(curl -s "$video_url" | sed -n -E ' /^