From 1b797bee3ecb85b21823867060bb60ca2bbf9079 Mon Sep 17 00:00:00 2001 From: ksyasuda Date: Sat, 4 Jun 2022 02:05:37 -0700 Subject: [PATCH 1/6] add autoplay flag for continue watching prompt after each episode --- ani-cli | 159 ++++++++++++++++++++++++++++++++--------------------- aniwrapper | 26 ++++++--- 2 files changed, 114 insertions(+), 71 deletions(-) diff --git a/ani-cli b/ani-cli index 552244b..affd907 100755 --- a/ani-cli +++ b/ani-cli @@ -754,6 +754,21 @@ episode_selection() { fi } +continue_watching() { + if ((IS_ROFI == 1)); then + choice=$(rofi -dmenu -dpi "$DPI" -config "$ROFI_CFG" \ + -theme-str 'listview {columns: 1;} window {width: 25%;}' \ + -i -l 2 -no-custom -sep '|' -a 0 -mesg "$(generate_span "Next episode: $((episode + 1))")" \ + -p "Continue watching $selection_id?:" -window-title 'aniwrapper' <<< "Yes|No") + else + inf "Continue watching $selection_id?" + prompt "Next episode -> $((episode + 1)) [y/n]" + read -r choice + fi + + [[ "$choice" =~ ^(y|Y|Yes)$ ]] && return 0 || return 1 +} + open_episode() { anime_id="$1" episode="$2" @@ -792,6 +807,14 @@ open_episode() { else ((SILENT != 1)) && inf "Playing $anime_id - Episode $episode" fi + if ((is_autoplay == 1)); then + wait "$PID" + if continue_watching; then + open_episode "$anime_id" "$((episode + 1))" "$ddir" + else + exit 0 + fi + fi else lg "Downloading episode $episode ..." dl_dir="${ddir// /}/$anime_id" @@ -851,8 +874,12 @@ parse_args() { quality=best is_download=0 is_resume=0 - while getopts 'd:Hsvq:cf:t:T:CQ:D:Sp:r' OPT; do + is_autoplay=0 + while getopts 'ad:Hsvq:cf:t:T:CQ:D:Sp:r' OPT; do case "$OPT" in + a) + is_autoplay=1 + ;; d) is_download=1 download_dir="$OPTARG" @@ -936,6 +963,71 @@ parse_args() { done } +show_menu() { + if ((SILENT != 1)); then + episode=${ep_choice_end:-$ep_choice_start} + choice='' + while :; do + inf "Currently playing $selection_id episode" "${episode// /}/$LAST_EP_NUMBER" + ((episode != LAST_EP_NUMBER)) && menu_line_alternate "next episode" "n" + ((episode != FIRST_EP_NUMBER)) && menu_line_alternate "previous episode" "p" + ((FIRST_EP_NUMBER != LAST_EP_NUMBER)) && menu_line_alternate "select episode" "s" + menu_line_alternate "replay current episode" "r" + menu_line_alternate "search for another anime" "a" + menu_line_alternate "download current episode" "d" + menu_line_alternate "download current episode (with quality selection)" "D" + menu_line_alternate "select video quality (current: $quality)" "Q" + menu_line_strong "exit" "q" + prompt "Enter choice" + read -r choice + case $choice in + n) + episode=$((episode + 1)) + ;; + p) + episode=$((episode - 1)) + ;; + + s) + episode_selection + episode=$ep_choice_start + ;; + + r) + episode=$((episode)) + ;; + a) + stream + episode=$ep_choice_start + lg "NEW EPISODE: $selection_id - $episode" + ;; + Q) + set_video_quality + episode=$((episode)) + ;; + + d) + get_dl_dir + is_download=1 + ;; + D) + get_dl_dir + set_video_quality + is_download=1 + ;; + q) + break + ;; + + *) + die "invalid choice" + ;; + esac + open_episode "$selection_id" "$episode" "$download_dir" + done + fi +} + main() { case $scrape in query) @@ -1012,72 +1104,13 @@ main() { open_episode "$selection_id" "$ep" "$download_dir" done - if [[ "$is_download" -eq 1 ]]; then + if ((is_download == 1)); then lg "Finished downloading episodes: $episodes for $selection_id... exiting" exit 0 fi - if ((SILENT != 1)); then - episode=${ep_choice_end:-$ep_choice_start} - choice='' - while :; do - inf "Currently playing $selection_id episode" "${episode// /}/$LAST_EP_NUMBER" - ((episode != LAST_EP_NUMBER)) && menu_line_alternate "next episode" "n" - ((episode != FIRST_EP_NUMBER)) && menu_line_alternate "previous episode" "p" - ((FIRST_EP_NUMBER != LAST_EP_NUMBER)) && menu_line_alternate "select episode" "s" - menu_line_alternate "replay current episode" "r" - menu_line_alternate "search for another anime" "a" - menu_line_alternate "download current episode" "d" - menu_line_alternate "download current episode (with quality selection)" "D" - menu_line_alternate "select video quality (current: $quality)" "Q" - menu_line_strong "exit" "q" - prompt "Enter choice" - read -r choice - case $choice in - n) - episode=$((episode + 1)) - ;; - p) - episode=$((episode - 1)) - ;; - - s) - episode_selection - episode=$ep_choice_start - ;; - - r) - episode=$((episode)) - ;; - a) - stream - episode=$ep_choice_start - lg "NEW EPISODE: $selection_id - $episode" - ;; - Q) - set_video_quality - episode=$((episode)) - ;; - - d) - get_dl_dir - is_download=1 - ;; - D) - get_dl_dir - set_video_quality - is_download=1 - ;; - q) - break - ;; - - *) - die "invalid choice" - ;; - esac - open_episode "$selection_id" "$episode" "$download_dir" - done + if ((is_autoplay == 0)); then + show_menu fi } diff --git a/aniwrapper b/aniwrapper index 94702b9..bfa32c7 100755 --- a/aniwrapper +++ b/aniwrapper @@ -16,6 +16,7 @@ SUPPORTED_PLAYERS="mpv|vlc" QUALITY=best PLAYER_FN=mpv DPI=96 +IS_AUTOPLAY=0 GET_QUALITY=0 IS_CUSTOM_THEME=0 IS_DOWNLOAD=0 @@ -87,23 +88,26 @@ run() { if ((IS_PLAY_FROM_FILE == 0 && IS_SYNC == 0 && GET_QUALITY == 1)); then get_quality fi + if ((IS_AUTOPLAY)); then + CMD="$CMD -a" + fi if ((SILENT == 1)); then if ((IS_CUSTOM_THEME == 0)); then - "$CMD" -D"$DPI" -Sq "$QUALITY" -t "$theme" -p "$PLAYER_FN" "$@" + $CMD -D"$DPI" -Sq "$QUALITY" -t "$theme" -p "$PLAYER_FN" "$@" else - "$CMD" -D"$DPI" -Sq "$QUALITY" -T "$CFG_FILE" -p "$PLAYER_FN" "$@" + $CMD -D"$DPI" -Sq "$QUALITY" -T "$CFG_FILE" -p "$PLAYER_FN" "$@" fi elif ((VERBOSE == 1)); then if ((IS_CUSTOM_THEME == 0)); then - "$CMD" -D"$DPI" -vq "$QUALITY" -t "$theme" -p "$PLAYER_FN" "$@" + $CMD -D"$DPI" -vq "$QUALITY" -t "$theme" -p "$PLAYER_FN" "$@" else - "$CMD" -D"$DPI" -vq "$QUALITY" -T "$CFG_FILE" -p "$PLAYER_FN" "$@" + $CMD -D"$DPI" -vq "$QUALITY" -T "$CFG_FILE" -p "$PLAYER_FN" "$@" fi else if ((IS_CUSTOM_THEME == 0)); then - "$CMD" -D"$DPI" -q "$QUALITY" -t "$theme" -p "$PLAYER_FN" "$@" + $CMD -D"$DPI" -q "$QUALITY" -t "$theme" -p "$PLAYER_FN" "$@" else - "$CMD" -D"$DPI" -q "$QUALITY" -T "$CFG_FILE" -p "$PLAYER_FN" "$@" + $CMD -D"$DPI" -q "$QUALITY" -T "$CFG_FILE" -p "$PLAYER_FN" "$@" fi fi } @@ -168,8 +172,11 @@ set_theme() { } parse_args() { - while getopts 'cCdD:f:hpqQ:rSt:T:v' OPT; do + while getopts 'acCdD:f:hpqQ:rSt:T:v' OPT; do case "$OPT" in + a) + IS_AUTOPLAY=1 + ;; c) IS_ROFI=0 lg "Command-line (ani-cli) mode set" @@ -267,6 +274,9 @@ check_flags() { if ((VERBOSE == 1 && SILENT == 1)); then die "verbose and silent options cannot be used together" fi + if ((IS_DOWNLOAD == 1 && IS_AUTOPLAY == 1)); then + die "autoplay and download options cannot be used together" + fi if ((IS_DOWNLOAD == 0 && IS_ALTERNATE_PLAYER == 1)); then get_player lg "SELECTED PLAYER FN -> $PLAYER_FN" @@ -347,7 +357,7 @@ main() { span=$(printf '%s\n%s\n' "$(generate_span "Provide a path to a valid directory, or choose from the list below")" "$(generate_span "The program will begin searching for media files from the supplied directory")") play_dir=$( rofi -dpi "$DPI" -dmenu -config "$CFG_FILE" \ - -l 12 -mesg "$span" -p "Enter path to starting directory:" \ + -i -l 12 -mesg "$span" -p "Enter path to starting directory:" \ -async-pre-read 24 -matching 'fuzzy' -window-title 'aniwrapper' \ -sort -sorting-method fzf \ < <(sqlite3 -noheader -list "$CFG_DIR/history.sqlite3" <<< "SELECT directory FROM file_history WHERE filename = 'DIRECTORY' ORDER BY WATCH_DATE DESC;") From 870920cbf5dc41edaee8b93d9b8a7a7189d48e11 Mon Sep 17 00:00:00 2001 From: ksyasuda Date: Sat, 4 Jun 2022 14:13:24 -0700 Subject: [PATCH 2/6] move anime_id from prompt to message in rofi prompt --- ani-cli | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ani-cli b/ani-cli index affd907..13a2933 100755 --- a/ani-cli +++ b/ani-cli @@ -756,10 +756,11 @@ episode_selection() { continue_watching() { if ((IS_ROFI == 1)); then + msg="$(printf '%s\n%s' "$(generate_span "Anime: $anime_id")" "$(generate_span "Next episode: $((episode + 1))")")" choice=$(rofi -dmenu -dpi "$DPI" -config "$ROFI_CFG" \ -theme-str 'listview {columns: 1;} window {width: 25%;}' \ - -i -l 2 -no-custom -sep '|' -a 0 -mesg "$(generate_span "Next episode: $((episode + 1))")" \ - -p "Continue watching $selection_id?:" -window-title 'aniwrapper' <<< "Yes|No") + -i -l 2 -no-custom -sep '|' -a 0 -mesg "$msg" \ + -p "Continue watching?" -window-title 'aniwrapper' <<< "Yes|No") else inf "Continue watching $selection_id?" prompt "Next episode -> $((episode + 1)) [y/n]" @@ -808,6 +809,7 @@ open_episode() { ((SILENT != 1)) && inf "Playing $anime_id - Episode $episode" fi if ((is_autoplay == 1)); then + lg "Waiting for video to finish playing..." wait "$PID" if continue_watching; then open_episode "$anime_id" "$((episode + 1))" "$ddir" From 8d6acddea6841f9dde434805911d0db8fb60dec1 Mon Sep 17 00:00:00 2001 From: ksyasuda Date: Sat, 4 Jun 2022 14:26:36 -0700 Subject: [PATCH 3/6] make yes default option autoplay prompt --- ani-cli | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ani-cli b/ani-cli index 13a2933..ff4c897 100755 --- a/ani-cli +++ b/ani-cli @@ -763,8 +763,9 @@ continue_watching() { -p "Continue watching?" -window-title 'aniwrapper' <<< "Yes|No") else inf "Continue watching $selection_id?" - prompt "Next episode -> $((episode + 1)) [y/n]" + prompt "Next episode -> $((episode + 1)) [Y/n]" read -r choice + [ -z "$choice" ] && choice="y" fi [[ "$choice" =~ ^(y|Y|Yes)$ ]] && return 0 || return 1 From 2e53ac3bfc584f29cf43e539771a35e6e05c547c Mon Sep 17 00:00:00 2001 From: ksyasuda Date: Sat, 4 Jun 2022 16:24:02 -0700 Subject: [PATCH 4/6] cleanup code --- ani-cli | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ani-cli b/ani-cli index ff4c897..10703b7 100755 --- a/ani-cli +++ b/ani-cli @@ -776,7 +776,6 @@ open_episode() { episode="$2" ddir="$3" - # Don't update watch history if downloading episode insert_history "watch" "$anime_id" "$episode" lg "Getting data for episode $episode" @@ -1110,9 +1109,7 @@ main() { if ((is_download == 1)); then lg "Finished downloading episodes: $episodes for $selection_id... exiting" exit 0 - fi - - if ((is_autoplay == 0)); then + elif ((is_autoplay == 0)); then show_menu fi } From e5772469c7986e2a6d5c7cdcd56123de0c7e3208 Mon Sep 17 00:00:00 2001 From: ksyasuda Date: Sat, 4 Jun 2022 16:24:06 -0700 Subject: [PATCH 5/6] update docs --- aniwrapper | 3 ++- docs/man/aniwrapper.1 | 21 +++++++++++++++++++-- docs/man/aniwrapper.1.md | 5 ++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/aniwrapper b/aniwrapper index bfa32c7..9b9bd63 100755 --- a/aniwrapper +++ b/aniwrapper @@ -36,12 +36,13 @@ help_text() { printf "%s\n" "$line" done <<< " Usage: - aniwrapper [-dhpqSv] [-t | -T ] [] + aniwrapper [-adhpqSv] [-t | -T ] [] aniwrapper -f [-t | -T ] [-pSv] []\ aniwrapper -c [-dhpqSv] [] aniwrapper -Q aniwrapper -C Options: + -a enable autoplay -c enable command-line mode (rofi disabled) -C connect to history database -d download episode in command-line mode diff --git a/docs/man/aniwrapper.1 b/docs/man/aniwrapper.1 index 8c8def7..6f5e56c 100644 --- a/docs/man/aniwrapper.1 +++ b/docs/man/aniwrapper.1 @@ -1,5 +1,19 @@ -.\" Automatically generated by Pandoc 2.14.2 +.\" Automatically generated by Pandoc 2.17.1.1 .\" +.\" Define V font for inline verbatim, using C font in formats +.\" that render this, and otherwise B font. +.ie "\f[CB]x\f[]"x" \{\ +. ftr V B +. ftr VI BI +. ftr VB B +. ftr VBI BI +.\} +.el \{\ +. ftr V CR +. ftr VI CI +. ftr VB CB +. ftr VBI CBI +.\} .TH "ANIWRAPPER" "1" "February 4, 2022" "aniwrapper 1.0.0" "Man Page" .hy .SH NAME @@ -8,7 +22,7 @@ aniwrapper - A rofi wrapper around ani-cli: a command-line tool to stream, download, and play anime .SH SYNOPSIS .PP -\f[B]aniwrapper\f[R] [-dhpqrSv] [-t \f[I]theme\f[R] | -T +\f[B]aniwrapper\f[R] [-adhpqrSv] [-t \f[I]theme\f[R] | -T \f[I]config_path\f[R]] [\f[I]query\f[R]] .PD 0 .P @@ -43,6 +57,9 @@ aniwrapper.rasi theme .IP \[bu] 2 best quality .TP +\f[B]-a\f[R] +Enable autoplay in streaming mode +.TP \f[B]-c\f[R] Enable command-line mode (disable \f[B]rofi\f[R]) .TP diff --git a/docs/man/aniwrapper.1.md b/docs/man/aniwrapper.1.md index 68dfed1..5c92990 100644 --- a/docs/man/aniwrapper.1.md +++ b/docs/man/aniwrapper.1.md @@ -12,7 +12,7 @@ aniwrapper - A rofi wrapper around ani-cli: a command-line tool to stream, downl # SYNOPSIS -**aniwrapper** [-dhpqrSv] [-t _theme_ | -T _config_path_] [_query_]\ +**aniwrapper** [-adhpqrSv] [-t _theme_ | -T _config_path_] [_query_]\ **aniwrapper** -f _directory_path_ [-t _theme_ | -T _config_path_] [-pSv] [_query_]\ **aniwrapper** -c [-dhpqrSv] [_query_]\ **aniwrapper** -Q _query_\ @@ -32,6 +32,9 @@ Defaults: - aniwrapper.rasi theme - best quality +**-a** +: Enable autoplay in streaming mode + **-c** : Enable command-line mode (disable **rofi**) From f218b34e2134528f5a39d57afd02ff8fd6be2b11 Mon Sep 17 00:00:00 2001 From: ksyasuda Date: Sat, 4 Jun 2022 16:37:55 -0700 Subject: [PATCH 6/6] make autoplay stop after last episode --- ani-cli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ani-cli b/ani-cli index 10703b7..bc8e234 100755 --- a/ani-cli +++ b/ani-cli @@ -811,7 +811,7 @@ open_episode() { if ((is_autoplay == 1)); then lg "Waiting for video to finish playing..." wait "$PID" - if continue_watching; then + if ((episode + 1 <= LAST_EP_NUMBER)) && continue_watching; then open_episode "$anime_id" "$((episode + 1))" "$ddir" else exit 0