From 8d359fef3176b1000de2ab4d56e2ae203f80bfb4 Mon Sep 17 00:00:00 2001 From: JimboKearn Date: Mon, 14 Jun 2021 14:52:02 +0530 Subject: [PATCH 1/5] feat: episode count to continue where we left off --- ani-cli | 52 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/ani-cli b/ani-cli index cfb6af5..e388b08 100755 --- a/ani-cli +++ b/ani-cli @@ -1,10 +1,11 @@ #!/bin/sh -# dependencies: sed curl video_player +# dependencies: sed curl jq video_player # video_player ( needs to be able to play urls ) player_fn="mpv" prog="ani-cli" +logfile="${XDG_CACHE_HOME:-$HOME/.cache}/ani-hsts" c_red="\033[1;31m" c_green="\033[1;32m" @@ -22,6 +23,7 @@ help_text () { USAGE: $prog -h show this help text -d download episode + -H watch where you left off EOF } @@ -92,11 +94,12 @@ dep_ch () { # Start Up # ############ -dep_ch "$player_fn" "curl" "sed" +dep_ch "$player_fn" "curl" "sed" "jq" # option parsing is_download=0 -while getopts 'hd' OPT; do +resume_watching=0 +while getopts 'hdH' OPT; do case $OPT in h) help_text @@ -105,23 +108,34 @@ while getopts 'hd' OPT; do d) is_download=1 ;; + H) + resume_watching=1 + ;; esac done shift $((OPTIND - 1)) # get query -if [ -z "$*" ]; then - printf "Search Anime: " - read -r query -else - query=$* -fi +[ $resume_watching -eq 0 ] && + if [ -z "$*" ]; then + printf "Search Anime: " + read -r query + else + query=$* + fi + +# create history file +[ -f $logfile ] || printf "{}" > $logfile ##################### ## Anime selection ## ##################### -search_results=$(search_anime "$query") +if [ $resume_watching -eq 0 ]; then + search_results=$(search_anime "$query") +else + search_results=$(jq -r 'keys[]' $logfile) +fi [ -z "$search_results" ] && die "No search results found" @@ -173,12 +187,16 @@ read last_ep_number </dev/null || die "Invalid number entered" @@ -217,6 +235,10 @@ open_episode () { esac if [ $is_download -eq 0 ]; then + # write anime and episode number + jq ".\"${selection_id}\" = $((ep+1))" $logfile > "${logfile}.new" \ + && mv "${logfile}.new" $logfile + setsid -f $player_fn "$video_url" >/dev/null 2>&1 else printf "Downloading episode $episode ...\n" From 22f223a4eceb10392eda58ed810039c8f48b4087 Mon Sep 17 00:00:00 2001 From: JimboKearn Date: Tue, 15 Jun 2021 20:46:30 +0530 Subject: [PATCH 2/5] replaced json with tsv --- ani-cli | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/ani-cli b/ani-cli index e388b08..aea317b 100755 --- a/ani-cli +++ b/ani-cli @@ -1,6 +1,6 @@ #!/bin/sh -# dependencies: sed curl jq video_player +# dependencies: grep sed curl video_player # video_player ( needs to be able to play urls ) player_fn="mpv" @@ -94,7 +94,7 @@ dep_ch () { # Start Up # ############ -dep_ch "$player_fn" "curl" "sed" "jq" +dep_ch "$player_fn" "curl" "sed" "grep" # option parsing is_download=0 @@ -125,7 +125,7 @@ shift $((OPTIND - 1)) fi # create history file -[ -f $logfile ] || printf "{}" > $logfile +[ -f $logfile ] || printf "" > $logfile ##################### ## Anime selection ## @@ -134,7 +134,7 @@ shift $((OPTIND - 1)) if [ $resume_watching -eq 0 ]; then search_results=$(search_anime "$query") else - search_results=$(jq -r 'keys[]' $logfile) + search_results=$(cut -f1 $logfile) fi [ -z "$search_results" ] && die "No search results found" @@ -195,7 +195,7 @@ if [ $resume_watching -eq 0 ]; then read ep_choice_start ep_choice_end printf "$c_reset" else - ep_choice_start=$(jq ".\"${selection_id}\"" $logfile) + ep_choice_start=$(awk "/${selection_id}/ { print \$2 }" $logfile) fi { # checking input @@ -236,8 +236,13 @@ open_episode () { if [ $is_download -eq 0 ]; then # write anime and episode number - jq ".\"${selection_id}\" = $((ep+1))" $logfile > "${logfile}.new" \ - && mv "${logfile}.new" $logfile + if $(grep -w "${selection_id}" $logfile >/dev/null); then + awk -F'\t' " + BEGIN {OFS=\"\\t\"}; NR != $choice; NR == $choice { \$2=$((episode+1));print } + " $logfile > "${logfile}.new" && mv "${logfile}.new" $logfile + else + printf "%s\t%d\n" "$selection_id" $((episode+1)) >> $logfile + fi setsid -f $player_fn "$video_url" >/dev/null 2>&1 else From 8c36d69ca6ed2dc74efd6563e559ac606fc06a48 Mon Sep 17 00:00:00 2001 From: JimboKearn Date: Fri, 18 Jun 2021 09:47:47 +0530 Subject: [PATCH 3/5] replaced awk and cut with sed --- ani-cli | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ani-cli b/ani-cli index aea317b..c567283 100755 --- a/ani-cli +++ b/ani-cli @@ -134,7 +134,7 @@ shift $((OPTIND - 1)) if [ $resume_watching -eq 0 ]; then search_results=$(search_anime "$query") else - search_results=$(cut -f1 $logfile) + search_results=$(sed -n -E 's/\t[0-9]*//p' $logfile) fi [ -z "$search_results" ] && die "No search results found" @@ -195,7 +195,7 @@ if [ $resume_watching -eq 0 ]; then read ep_choice_start ep_choice_end printf "$c_reset" else - ep_choice_start=$(awk "/${selection_id}/ { print \$2 }" $logfile) + ep_choice_start=$(sed -n -E "s/${selection_id}\t//p" $logfile) fi { # checking input @@ -237,8 +237,8 @@ open_episode () { if [ $is_download -eq 0 ]; then # write anime and episode number if $(grep -w "${selection_id}" $logfile >/dev/null); then - awk -F'\t' " - BEGIN {OFS=\"\\t\"}; NR != $choice; NR == $choice { \$2=$((episode+1));print } + sed -E " + s/^${selection_id}\t[0-9]+/${selection_id}\t$((episode+1))/ " $logfile > "${logfile}.new" && mv "${logfile}.new" $logfile else printf "%s\t%d\n" "$selection_id" $((episode+1)) >> $logfile From 6d65ba099d28792587767588e6d609e0a67eed7e Mon Sep 17 00:00:00 2001 From: JimboKearn Date: Fri, 18 Jun 2021 12:23:06 +0530 Subject: [PATCH 4/5] minor tweaks --- ani-cli | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ani-cli b/ani-cli index c567283..e775978 100755 --- a/ani-cli +++ b/ani-cli @@ -209,6 +209,10 @@ fi fi } +# add anime to history file +grep -q -w "${selection_id}" $logfile || + printf "%s\t%d\n" "$selection_id" $((episode+1)) >> $logfile + open_episode () { anime_id=$1 episode=$2 @@ -236,13 +240,9 @@ open_episode () { if [ $is_download -eq 0 ]; then # write anime and episode number - if $(grep -w "${selection_id}" $logfile >/dev/null); then - sed -E " - s/^${selection_id}\t[0-9]+/${selection_id}\t$((episode+1))/ - " $logfile > "${logfile}.new" && mv "${logfile}.new" $logfile - else - printf "%s\t%d\n" "$selection_id" $((episode+1)) >> $logfile - fi + sed -E " + s/^${selection_id}\t[0-9]+/${selection_id}\t$((episode+1))/ + " $logfile > "${logfile}.new" && mv "${logfile}.new" $logfile setsid -f $player_fn "$video_url" >/dev/null 2>&1 else From 01197405b7d0409193e21aa575990b64da43c931 Mon Sep 17 00:00:00 2001 From: JimboKearn Date: Fri, 18 Jun 2021 12:30:24 +0530 Subject: [PATCH 5/5] Updated README.md --- README.md | 4 ++++ ani-cli | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0e8976c..45d2aad 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,9 @@ This tool scrapes the site [gogoanime](https://gogoanime.vc). # download anime ani-cli -d + # resume watching anime + ani-cli -H + Multiple episodes can be viewed/downloaded by giving the episode range like so Choose episode [1-13]: 1 6 @@ -21,6 +24,7 @@ This would open/download episodes 1 2 3 4 5 6 ## Dependencies +* grep * curl * sed * mpv diff --git a/ani-cli b/ani-cli index e775978..34eab65 100755 --- a/ani-cli +++ b/ani-cli @@ -23,7 +23,7 @@ help_text () { USAGE: $prog -h show this help text -d download episode - -H watch where you left off + -H continue where you left off EOF }