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"