From 072680d637e87ce133f171c60e75a3e0adddabd1 Mon Sep 17 00:00:00 2001 From: ksyasuda Date: Thu, 30 Dec 2021 16:47:08 -0800 Subject: [PATCH] clean up code a bit and update downloads logic fix script inserting into watch_history when downloading modify logic so script quits immediately once done downloading episode(s) --- ani-cli | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/ani-cli b/ani-cli index 3e37277..3772c05 100755 --- a/ani-cli +++ b/ani-cli @@ -315,19 +315,10 @@ get_search_query() { anime_selection() { # Select anime from query results search_results=$* - # menu_format_string='[%d] %s\n' - # menu_format_string_c1="$c_blue[$c_cyan%d$c_blue] $c_reset%s\n" - # menu_format_string_c2="$c_blue[$c_cyan%d$c_blue] $c_yellow%s$c_reset\n" - count=1 menu=() res=() while read -r anime_id; do - # alternating colors for menu - # [ $((count % 2)) -eq 0 ] && - # menu_format_string=$menu_format_string_c1 || - # menu_format_string=$menu_format_string_c2 - menu+="$count. $anime_id\n" idx=$((count - 1)) res["$idx"]="$anime_id" @@ -475,10 +466,11 @@ open_episode() { log "Getting data for episode $episode" - insert_history "$anime_id" "$episode" + # Don't update watch history if downloading episode + if [ "$is_download" -eq 0 ]; then + insert_history "$anime_id" "$episode" + fi - # embedded_video_url=$(get_embedded_video_link "$anime_id" "$episode") - # video_url=$(get_links "$embedded_video_url") get_video_quality status_code=$(curl -s -I get_video_quality "$play_link" | head -n 1|cut -d ' ' -f2) log "Status code: $status_code" @@ -503,8 +495,8 @@ open_episode() { ffmpeg -i "$play_link" -c copy "${episode}.mkv" >/dev/null 2>&1 && notify-send -i "$ANIWRAPPER_ICON_PATH" "Download complete for ${anime_id//-/ } - Episode: $episode" || notify-send -i "$ANIWRAPPER_ICON_PATH" "Download failed for ${anime_id//-/ } - Episode: $episode. Please retry or check your internet connection" - # printf "${c_green}Downloaded episode: %s${c_reset}\n" "$episode" || - # printf "${c_red}Download failed episode: %s , please retry or check your internet connection${c_reset}\n" "$episode" + # printf "${c_green}Downloaded episode: %s${c_reset}\n" "$episode" || + # printf "${c_red}Download failed episode: %s , please retry or check your internet connection${c_reset}\n" "$episode" } fi } @@ -535,7 +527,6 @@ while getopts 'hd:Hpa:P:svq:' OPT; do d) is_download=1 download_dir="$OPTARG" - log "DOWNLOAD DIR: $download_dir" ;; H) @@ -706,6 +697,9 @@ done if [[ "$is_add" -eq 1 ]]; then log "Finished adding to playlist file... exiting" exit 0 +elif [[ "$is_download" -eq 1 ]]; then + log "Finished downloading episodes: $episodes for $selection_id... exiting" + exit 0 fi episode=${ep_choice_end:-$ep_choice_start}