From 2bab68a887ed901e1aa0baa7dd4eaba20a0651e5 Mon Sep 17 00:00:00 2001 From: Kyle Yasuda <33813108+ksyasuda@users.noreply.github.com> Date: Tue, 19 Jul 2022 00:10:38 -0700 Subject: [PATCH] add menu and option for selecting provider to scrape (#14) --- ani-cli | 6 +++++- aniwrapper | 44 +++++++++++++++++++++++++++++++++++++++- docs/man/aniwrapper.1 | 5 ++++- docs/man/aniwrapper.1.md | 3 +++ 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/ani-cli b/ani-cli index d321543..f0a7847 100755 --- a/ani-cli +++ b/ani-cli @@ -446,7 +446,7 @@ parse_args() { is_download=0 is_resume=0 is_autoplay=0 - while getopts 'ad:Hsvq:cf:t:T:CQ:D:Sp:rR' OPT; do + while getopts 'ad:Hsvq:cf:t:T:CQ:D:Sp:P:rR' OPT; do case "$OPT" in a) is_autoplay=1 @@ -531,6 +531,10 @@ parse_args() { die "ERROR: $PLAYER_FN does not exist" fi ;; + P) + select_provider="$OPTARG" + ((select_provider < 1 || select_provider > 7)) && die "Invalid provider: $select_provider" + ;; *) inf "Invalid option" exit 1 diff --git a/aniwrapper b/aniwrapper index f35ddfa..a41facd 100755 --- a/aniwrapper +++ b/aniwrapper @@ -22,6 +22,7 @@ IS_ROFI=1 IS_SYNC=0 IS_ALTERNATE_PLAYER=0 IS_VERBOSE=0 +SELECT_PROVIDER=0 SILENT=0 quit="8. Quit" @@ -46,6 +47,7 @@ Options: -f (no trailing slash) specify starting directory for play for file mode -h show this help text -p enable player selection menu + -P select provider to scrape first -q enable quality selection -Q query the history database -r start script in episode selection using the most recently watched anime @@ -155,7 +157,7 @@ set_theme() { } parse_args() { - while getopts 'acCdD:f:hpqQ:rSt:T:v' OPT; do + while getopts 'acCdD:f:hpPqQ:rSt:T:v' OPT; do case "$OPT" in a) IS_AUTOPLAY=1 @@ -189,6 +191,9 @@ parse_args() { p) IS_ALTERNATE_PLAYER=1 ;; + P) + SELECT_PROVIDER=1 + ;; q) GET_QUALITY=1 lg "Quality prompt enabled" @@ -252,6 +257,37 @@ get_player() { fi } +# prompts the user to select a provider and returns the provider name and index +get_provider() { + providers="1. Mp4upload|2. Doodstream|3. Streamlare|4. Okru|5. Xstreamcdn|6. Animixplay|7. Gogoanime" + if ((IS_ROFI)); then + selection="$(rofi -dmenu -config "$CFG_FILE" -DPI "$DPI" \ + -i -l 7 -theme-str 'listview {columns: 1;} window {width: 45%;}' \ + -p "Select provider:" -window-title 'aniwrapper' \ + -a 0 -sep '|' <<< "$providers")" + [ -z "$selection" ] && selection=1 + provider_idx="${selection:0:1}" + else + printf "%s%s\n" "Select provider:" "[$providers]" + prompt "Enter provider [1-7]" + read -r provider_idx + [ -z "$provider_idx" ] && die "ERROR: provider index cannot be empty" + ((provider_idx < 1 || provider_idx > 7)) && die "ERROR: provider index must be between 1 and 7" + fi + while IFS='|' read -ra providers_list; do + for p in "${providers_list[@]}"; do + if [[ "${p:0:1}" == "$provider_idx" ]]; then + lg "provider -> $p | provider index -> $idx" > /dev/stderr + provider="${p:3}" + break + fi + ((++idx)) + done + done <<< "$providers" + [ -z "$provider" ] && provider="mp4upload" + inf "Selected provider: $provider" +} + # Check passed in flags and set cli arguments check_flags() { if ((IS_VERBOSE && SILENT)); then @@ -293,6 +329,12 @@ check_flags() { if ((IS_RESUME)); then args+=(-r) fi + if ((SELECT_PROVIDER)); then + get_provider || provider_idx=1 + lg "PROVIDER INDEX -> $provider_idx" + lg "SELECTED PROVIDER -> $provider" + args+=(-P"$provider_idx") + fi if ((SILENT)); then args+=(-S) fi diff --git a/docs/man/aniwrapper.1 b/docs/man/aniwrapper.1 index 6f5e56c..658fdc1 100644 --- a/docs/man/aniwrapper.1 +++ b/docs/man/aniwrapper.1 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pandoc 2.17.1.1 +.\" Automatically generated by Pandoc 2.18 .\" .\" Define V font for inline verbatim, using C font in formats .\" that render this, and otherwise B font. @@ -79,6 +79,9 @@ Display the help message \f[B]-p\f[R] Enable video player selection menu .TP +\f[B]-P\f[R] +Enable provider selection menu +.TP \f[B]-q\f[R] Enable quality selection .TP diff --git a/docs/man/aniwrapper.1.md b/docs/man/aniwrapper.1.md index 5c92990..d795c0b 100644 --- a/docs/man/aniwrapper.1.md +++ b/docs/man/aniwrapper.1.md @@ -53,6 +53,9 @@ Defaults: **-p** : Enable video player selection menu +**-P** +: Enable provider selection menu + **-q** : Enable quality selection