From fd83a8c4a4f3d74c36f77d755d8c3b1c7f062f2d Mon Sep 17 00:00:00 2001 From: ksyasuda Date: Mon, 8 Nov 2021 00:41:30 -0800 Subject: [PATCH] fix downloading to specific directory update config directory name ani-cli -> aniwrapper deprecate text-based history file --- ani-cli | 71 ++++++++++++++++++++++----------------------------------- 1 file changed, 27 insertions(+), 44 deletions(-) diff --git a/ani-cli b/ani-cli index 18f224b..b2e1a65 100755 --- a/ani-cli +++ b/ani-cli @@ -6,20 +6,18 @@ if [[ -z "$XDG_CONFIG_HOME" ]]; then fi BASE_URL="https://gogoanime.cm" -CFG_DIR="$XDG_CONFIG_HOME/ani-cli" +CFG_DIR="$XDG_CONFIG_HOME/aniwrapper" ROFI_CFG="meh.rasi" -HISTORY_DB="$XDG_CONFIG_HOME/ani-cli/history.sqlite3" +HISTORY_DB="$XDG_CONFIG_HOME/aniwrapper/history.sqlite3" -# dependencies: grep sed curl video_player +# dependencies: grep, sed, curl, video_player, rofi, sqlite3 # video_player ( needs to be able to play urls ) player_fn="mpv" prog="ani-cli" logfile="${XDG_CACHE_HOME:-$HOME/.cache}/ani-hsts" -# sql=$(sqlite3 -noheader "$HISTORY_DB") - c_red="\033[1;31m" c_green="\033[1;32m" c_yellow="\033[1;33m" @@ -56,7 +54,7 @@ search_anime() { curl -s "$BASE_URL//search.html" \ -G \ -d "keyword=$search" | - sed -n -E 's_^[[:space:]]*"${logfile}.new" && mv "${logfile}.new" "$logfile" + # sed -E " + # s/^${selection_id}\t[0-9]+/${selection_id}\t$((episode + 1))/ + # " "$logfile" >"${logfile}.new" && mv "${logfile}.new" "$logfile" setsid -f $player_fn --http-header-fields="Referer: $dpage_url" "$video_url" >/dev/null 2>&1 - # $player_fn --http-header-fields="Referer: $dpage_url" "$video_url" else printf "Downloading episode $episode ...\n" printf "%s\n" "$video_url" # add 0 padding to the episode name episode=$(printf "%03d" $episode) { - # ( - # echo "$DDIR" - # cd "$ddir" || return 1 - # mkdir -p "$anime_id" && cd "$anime_id" || return 1 - # ffmpeg -headers "Referer: $dpage_url" -i "$video_url" \ - # -codec copy "${anime_id}-${episode}.mkv" >/dev/null 2>&1 && - # printf "${c_green}Downloaded episode: %s${c_reset}\n" "$episode" || - # printf "${c_red}Download failed episode: %s${c_reset}\n" "$episode" - # ) - ( - echo "$DDIR" - cd "$ddir" || return 1 - mkdir -p "$anime_id" && cd "$anime_id" || return 1 - ffmpeg -headers "Referer: $dpage_url" -i "$video_url" \ - -codec copy "${anime_id}-${episode}.mkv" >/dev/null 2>&1 && - notify-send "Downloaded episode: $episode" || - notify-send "Download failed episode: $episode" - ) + cd "${ddir/ //}" || die "Could not enter directory $ddir" + mkdir -p "$anime_id" || die "Could not create directory" + cd "$anime_id" || die "Could not enter subdirectory $ddir/$anime_id" + ffmpeg -headers "Referer: $dpage_url" -i "$video_url" \ + -codec copy "${anime_id}-${episode}.mkv" >/dev/null 2>&1 && + notify-send "Downloaded episode: $episode" || + notify-send "Download failed episode: $episode" } fi } @@ -457,7 +439,7 @@ open_episode() { # to clear the colors when exited using SIGINT trap "printf '$c_reset'" INT HUP -dep_ch "$player_fn" "curl" "sed" "grep" +dep_ch "$player_fn" "curl" "sed" "grep" "sqlite3" "rofi" # option parsing is_download=0 @@ -542,6 +524,7 @@ case $scrape in search_results=$(printf "%s\n" "$stmt" | sqlite3 -noheader "$HISTORY_DB") [ -z "$search_results" ] && die "History is empty" anime_selection "${search_results[@]}" + [ $? -ne 0 ] && die "No anime selection found" stmt="SELECT episode_number FROM watch_history ORDER BY watch_date DESC LIMIT 1" run_stmt "$stmt" ep_choice_start=$? @@ -598,15 +581,17 @@ esac } # add anime to history file -grep -q -w "${selection_id}" "$logfile" || - printf "%s\t%d\n" "$selection_id" $((episode + 1)) >>"$logfile" +# grep -q -w "${selection_id}" "$logfile" || +# printf "%s\t%d\n" "$selection_id" $((episode + 1)) >>"$logfile" for ep in $episodes; do if [[ "$is_add" -eq 1 ]]; then - echo "ID: $selection_id" - echo "EPISODES: $episodes" + if [[ "$VERBOSE" -eq 1 ]]; then + printf "%s\n" "ID: $selection_id" + printf "%s\n" "EPISODES: $episodes" + fi printf "%s\n" "$selection_id $ep" >>"$playlist_file" - echo "Added to playlist file" + [ "$VERBOSE" -eq 1 ] && printf "%s\n" "Added to playlist file" exit 0 else open_episode "$selection_id" "$ep" "$download_dir" @@ -629,8 +614,6 @@ while :; do printf "$c_reset" read choice - # choice=$(printf '%s\n' "${args[@]}" | rofi -dmenu -l 8 -i -p "Enter choice:") - # choice=$(printf '%s\n' "$choice" | awk '{print $1}') printf "$c_reset" case $choice in n)