Add episode selection param (#18)

* fix quality selection

* add episode selection argument

* fix quality selection menu appearing when flag not set

* fix episode selection appearing when no episodes released yet

* update readme

* update readme

* make selected quality the default if watching/downloading multiple episodes
This commit is contained in:
Kyle Yasuda 2022-10-06 20:17:48 -07:00 committed by GitHub
parent da45bf15fe
commit fd954e7ede
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 88 additions and 59 deletions

View File

@ -145,6 +145,7 @@ aniwrapper -c # Use ani-cli command-line mode (rofi disabled)
aniwrapper -C # Connect to history database aniwrapper -C # Connect to history database
aniwrapper -d # Download anime in command-line mode aniwrapper -d # Download anime in command-line mode
aniwrapper -d <query> # Run in download mode (best quality), searching for <query> aniwrapper -d <query> # Run in download mode (best quality), searching for <query>
aniwrapper -e <episode> or <begin_episode - end_episode>
aniwrapper -f <starting_directory> # Specify starting directory for play_from_file mode, bypassing main menu aniwrapper -f <starting_directory> # Specify starting directory for play_from_file mode, bypassing main menu
aniwrapper -h # Show help menu aniwrapper -h # Show help menu
aniwrapper -p # Enable player selection menu aniwrapper -p # Enable player selection menu
@ -262,37 +263,6 @@ Change aniwrapper theme
</details> </details>
## ani-cli
```
# watch anime
ani-cli <query>
# verbose logging
ani-cli -v
# download anime
ani-cli -d <download_directory>
# resume watching anime
ani-cli -H
# sync history across devices
ani-cli -s
# choose quality
ani-cli -q <best (default)|1080p|720p|480p|360p|worst>
# choose rofi theme from presets
ani-cli -t <aniwrapper (default)|dracula|fancy|material|monokai|nord|nord2|onedark>
# Specify starting directory for play_from_file mode (does not work with -c)
ani-cli -f <starting_directory>
# run ani-cli in command-line mode (rofi disabled)
ani-cli -c
```
# Themes # Themes
<div align="center"> <div align="center">

62
ani-cli
View File

@ -12,10 +12,12 @@ ROFI_THEME="aniwrapper.rasi"
THEMES="alter|aniwrapper|dracula|doomone|fancy|material|monokai|nord|nord2|onedark" THEMES="alter|aniwrapper|dracula|doomone|fancy|material|monokai|nord|nord2|onedark"
TMPDIR="${XDG_CACHE_HOME:-$HOME/.cache}/aniwrapper-temp" TMPDIR="${XDG_CACHE_HOME:-$HOME/.cache}/aniwrapper-temp"
DPI=96 DPI=96
GET_QUALITY=0
IS_ROFI=1 IS_ROFI=1
VERBOSE=0 VERBOSE=0
SILENT=0 SILENT=0
FIRST_EP_NUMBER=1 FIRST_EP_NUMBER=1
NEW_QUALITY=0
PLAYER_FN="mpv" PLAYER_FN="mpv"
PID=0 PID=0
@ -182,8 +184,14 @@ get_video_link() {
: $((i += 1)) : $((i += 1))
done done
if printf '%s' "$result_links" | grep -q "m3u8"; then if printf '%s' "$result_links" | grep -q "m3u8"; then
lg "Using m3u8 link"
# if a new quality has not been selected already, then get video quality
# from user
((GET_QUALITY && !NEW_QUALITY)) && set_video_quality
get_video_quality_m3u8 "$result_links" get_video_quality_m3u8 "$result_links"
else else
lg "Using mp4 link"
((GET_QUALITY && !NEW_QUALITY)) && set_video_quality
video_url=$(get_video_quality_mp4 "$result_links") video_url=$(get_video_quality_mp4 "$result_links")
fi fi
unset result_links unset result_links
@ -223,6 +231,7 @@ process_search() {
episode_list() { episode_list() {
select_ep_result=$(curl -A "$AGENT" -s "$BASE_URL/v1/$1" | sed -nE "s_.*epslistplace.*>(.*)</div>_\1_p" | tr "," "\n" | sed -e '/extra/d' -e '/PV/d' | sed -nE 's_".*":"(.*)".*_\1_p') select_ep_result=$(curl -A "$AGENT" -s "$BASE_URL/v1/$1" | sed -nE "s_.*epslistplace.*>(.*)</div>_\1_p" | tr "," "\n" | sed -e '/extra/d' -e '/PV/d' | sed -nE 's_".*":"(.*)".*_\1_p')
lg "Select Episode Result: $select_ep_result"
FIRST_EP_NUMBER=1 FIRST_EP_NUMBER=1
[ -z "$select_ep_result" ] && LAST_EP_NUMBER=0 || LAST_EP_NUMBER=$(printf "%s\n" "$select_ep_result" | wc -l) [ -z "$select_ep_result" ] && LAST_EP_NUMBER=0 || LAST_EP_NUMBER=$(printf "%s\n" "$select_ep_result" | wc -l)
lg "First Ep #: $FIRST_EP_NUMBER | Last Ep #: $LAST_EP_NUMBER" lg "First Ep #: $FIRST_EP_NUMBER | Last Ep #: $LAST_EP_NUMBER"
@ -299,6 +308,24 @@ open_episode() {
fi fi
} }
# Sets $ep_choice_start = 1 if only one episode exists
# else call episode_selection
get_episode() {
[[ "$LAST_EP_NUMBER" -eq 0 ]] && die "Episodes not released yet for $anime_id"
if ((!is_select_episodes)); then
read -r ep_choice_start ep_choice_end <<< "${episodes//-/}"
# error if ep_choice_start is not a number
[[ -z "$ep_choice_start" || ! "$ep_choice_start" =~ ^[0-9]+$ ]] && die "Invalid episode number: ${ep_choice_start:-NULL}"
# if ep_choice_end is not a number, set it to ep_choice_start
[[ -n "$ep_choice_end" && ! "$ep_choice_end" =~ ^[0-9]+$ ]] && ep_choice_end="$ep_choice_start"
elif (((FIRST_EP_NUMBER == LAST_EP_NUMBER && (FIRST_EP_NUMBER == 0 || FIRST_EP_NUMBER == 1)))); then
ep_choice_start=1
else
episode_selection
fi
}
stream() { stream() {
lg "Running stream()" lg "Running stream()"
if [ "$#" -eq 0 ]; then if [ "$#" -eq 0 ]; then
@ -322,21 +349,18 @@ stream() {
die "No anime selection found" die "No anime selection found"
fi fi
fi fi
if (((FIRST_EP_NUMBER == LAST_EP_NUMBER && (FIRST_EP_NUMBER == 0 || FIRST_EP_NUMBER == 1)))); then get_episode
ep_choice_start=1
else
episode_selection
fi
} }
parse_args() { parse_args() {
download_dir="." download_dir="."
scrape=query scrape=query
quality=best quality=best
is_select_episodes=1
is_download=0 is_download=0
is_resume=0 is_resume=0
is_autoplay=0 is_autoplay=0
while getopts 'ad:Hsvq:cf:t:T:CQ:D:Sp:P:rR' OPT; do while getopts 'ad:e:Hsvqcf:t:T:CQ:D:Sp:P:rR' OPT; do
case "$OPT" in case "$OPT" in
a) a)
is_autoplay=1 is_autoplay=1
@ -346,6 +370,11 @@ parse_args() {
download_dir="$OPTARG" download_dir="$OPTARG"
lg "DOWNLOAD DIR: $download_dir" lg "DOWNLOAD DIR: $download_dir"
;; ;;
e)
episodes="$OPTARG"
[[ "$episodes" =~ ^[0-9]+(-[0-9]+)? ]] || die "Invalid episode range: $episodes"
is_select_episodes=0
;;
r) r)
is_resume=1 is_resume=1
;; ;;
@ -362,8 +391,7 @@ parse_args() {
VERBOSE=1 VERBOSE=1
;; ;;
q) q)
quality="$OPTARG" GET_QUALITY=1
lg "passed in quality: $quality"
;; ;;
c) c)
IS_ROFI=0 IS_ROFI=0
@ -461,7 +489,7 @@ show_menu() {
;; ;;
s) s)
episode_selection get_episode
episode=$ep_choice_start episode=$ep_choice_start
;; ;;
@ -489,7 +517,8 @@ show_menu() {
is_download=1 is_download=1
;; ;;
q) q)
break lg "Exiting..."
exit 0
;; ;;
*) *)
@ -577,7 +606,7 @@ main() {
anime_name="${updated_episode%%/*}" anime_name="${updated_episode%%/*}"
lg "ANIME NAME: $anime_name" lg "ANIME NAME: $anime_name"
if ! check_db "search" "$anime_name"; then if ! check_db "search" "$anime_name"; then
stmt="SELECT COUNT(*) FROM watch_history WHERE anime_name = '$anime_name' AND episode_number = '${updated_episode##*/ep}';" stmt="SELECT COUNT(*) FROM search_history WHERE anime_name = '$anime_name';"
lg "QUERY: $stmt" lg "QUERY: $stmt"
if [[ "$(run_stmt "$stmt")" -ne 0 ]]; then if [[ "$(run_stmt "$stmt")" -ne 0 ]]; then
lg "$updated_episode watched before... adding to watched list" lg "$updated_episode watched before... adding to watched list"
@ -593,11 +622,9 @@ main() {
die "No selection made" die "No selection made"
fi fi
lg "SELECTION: $selection" lg "SELECTION: $selection"
# get everything before -episode-
selection_id="${selection%%/*}" selection_id="${selection%%/*}"
# get everything after -episode-
ep_choice_start="${selection##*/ep}"
episode_list "$selection_id" episode_list "$selection_id"
get_episode
;; ;;
esac esac
@ -605,13 +632,14 @@ main() {
for ep in $episodes; do for ep in $episodes; do
open_episode "$selection_id" "$ep" "$download_dir" open_episode "$selection_id" "$ep" "$download_dir"
sleep 2 wait
((is_download)) && sleep 2
done done
if ((is_download)); then if ((is_download)); then
lg "Finished downloading episodes: $episodes for $selection_id... exiting" notification "Finished downloading episodes: $episodes for $selection_id... exiting"
exit 0 exit 0
elif ((!is_autoplay)); then elif ((!is_autoplay && is_select_episodes)); then
show_menu show_menu
fi fi
} }

View File

@ -8,7 +8,7 @@ CFG_FILE="$CFG_DIR/themes/aniwrapper.rasi"
DEFAULT_DOWNLOAD="$HOME/Videos/sauce" DEFAULT_DOWNLOAD="$HOME/Videos/sauce"
ROFI_THEME="aniwrapper.rasi" ROFI_THEME="aniwrapper.rasi"
THEMES="alter|aniwrapper|dracula|doomone|fancy|material|monokai|nord|nord2|onedark" THEMES="alter|aniwrapper|dracula|doomone|fancy|material|monokai|nord|nord2|onedark"
QUALITIES="1. best|2. 1080p|3. 720p|4. 480p|5. 360p|6. worst" QUALITIES="1. best|2. worst"
SUPPORTED_PLAYERS="mpv|vlc" SUPPORTED_PLAYERS="mpv|vlc"
QUALITY=best QUALITY=best
PLAYER_FN=mpv PLAYER_FN=mpv
@ -22,6 +22,7 @@ IS_ROFI=1
IS_SYNC=0 IS_SYNC=0
IS_ALTERNATE_PLAYER=0 IS_ALTERNATE_PLAYER=0
IS_VERBOSE=0 IS_VERBOSE=0
IS_SELECT_EPISODE=1
SELECT_PROVIDER=0 SELECT_PROVIDER=0
SILENT=0 SILENT=0
@ -34,9 +35,9 @@ help_text() {
printf "%s\n" "$line" printf "%s\n" "$line"
done <<< " done <<< "
Usage: Usage:
aniwrapper [-adhpqSv] [-t <theme> | -T <config_path>] [<query>] aniwrapper [-adehpqSv] [-t <theme> | -T <config_path>] [<query>]
aniwrapper -f <directory_path> [-t <theme> | -T <config_path>] [-pSv] [<query>]\ aniwrapper -f <directory_path> [-t <theme> | -T <config_path>] [-pSv] [<query>]\
aniwrapper -c [-dhpqSv] [<query>] aniwrapper -c [-dehpqSv] [<query>]
aniwrapper -Q <query> aniwrapper -Q <query>
aniwrapper -C aniwrapper -C
Options: Options:
@ -44,6 +45,7 @@ Options:
-c enable command-line mode (rofi disabled) -c enable command-line mode (rofi disabled)
-C connect to history database -C connect to history database
-d download episode in command-line mode -d download episode in command-line mode
-e [<episode> | <begin> - <end>] select episode(s) to stream/download
-f <path_to_directory> (no trailing slash) specify starting directory for play for file mode -f <path_to_directory> (no trailing slash) specify starting directory for play for file mode
-h show this help text -h show this help text
-p enable player selection menu -p enable player selection menu
@ -85,9 +87,6 @@ quit() {
} }
run() { run() {
if ((!IS_PLAY_FROM_FILE && !IS_SYNC && GET_QUALITY)); then
get_quality
fi
if ((IS_CUSTOM_THEME)); then if ((IS_CUSTOM_THEME)); then
args+=(-T"$CFG_FILE") args+=(-T"$CFG_FILE")
elif ((!IS_CUSTOM_THEME)); then elif ((!IS_CUSTOM_THEME)); then
@ -106,7 +105,7 @@ get_quality() {
-sep '|' -no-custom <<< "$QUALITIES") -sep '|' -no-custom <<< "$QUALITIES")
QUALITY=$(awk '{print $2}' <<< "$selection") QUALITY=$(awk '{print $2}' <<< "$selection")
else else
qualities="best|1080p|720p|480p|360p|worst" qualities="best|worst"
prompt "Choose quality " "[$qualities]" prompt "Choose quality " "[$qualities]"
read -r QUALITY read -r QUALITY
while [[ ! "$QUALITY" =~ ($qualities) ]]; do while [[ ! "$QUALITY" =~ ($qualities) ]]; do
@ -157,7 +156,7 @@ set_theme() {
} }
parse_args() { parse_args() {
while getopts 'acCdD:f:hpPqQ:rSt:T:v' OPT; do while getopts 'acCdD:e:f:hpPqQ:rSt:T:v' OPT; do
case "$OPT" in case "$OPT" in
a) a)
IS_AUTOPLAY=1 IS_AUTOPLAY=1
@ -178,6 +177,11 @@ parse_args() {
D) D)
DPI="$OPTARG" DPI="$OPTARG"
;; ;;
e)
episodes="$OPTARG"
[[ "$episodes" =~ ^[0-9]+(-[0-9]+)? ]] || die "Invalid episode range: $episodes"
IS_SELECT_EPISODE=0
;;
f) f)
IS_PLAY_FROM_FILE=1 IS_PLAY_FROM_FILE=1
play_path="$OPTARG" play_path="$OPTARG"
@ -342,6 +346,12 @@ check_flags() {
if ((IS_VERBOSE)); then if ((IS_VERBOSE)); then
args+=(-v) args+=(-v)
fi fi
if ((GET_QUALITY)); then
args+=(-q)
fi
if ((!IS_SELECT_EPISODE)); then
args+=(-e"$episodes")
fi
lg "ARGS: ${args[*]}" lg "ARGS: ${args[*]}"
if ((IS_AUTOPLAY || IS_DOWNLOAD || !IS_ROFI || IS_RESUME || IS_PLAY_FROM_FILE)); then if ((IS_AUTOPLAY || IS_DOWNLOAD || !IS_ROFI || IS_RESUME || IS_PLAY_FROM_FILE)); then

View File

@ -1,4 +1,4 @@
.\" Automatically generated by Pandoc 2.18 .\" Automatically generated by Pandoc 2.19.2
.\" .\"
.\" Define V font for inline verbatim, using C font in formats .\" Define V font for inline verbatim, using C font in formats
.\" that render this, and otherwise B font. .\" that render this, and otherwise B font.
@ -70,6 +70,9 @@ Connect to the history database
\f[B]-d\f[R] \f[B]-d\f[R]
Enable downloading anime in command-line mode Enable downloading anime in command-line mode
.TP .TP
\f[B]-e\f[R] \f[I]episode\f[R] \f[B]or\f[R] \f[I]begin_episode - end_episode\f[R]
Select episode(s) to stream/download
.TP
\f[B]-f\f[R] \f[B]-f\f[R]
Specify the starting search directory for \[lq]Play from File\[rq] mode Specify the starting search directory for \[lq]Play from File\[rq] mode
.TP .TP

View File

@ -44,6 +44,9 @@ Defaults:
**-d** **-d**
: Enable downloading anime in command-line mode : Enable downloading anime in command-line mode
**-e** _episode_ **or** _begin_episode - end_episode_
: Select episode(s) to stream/download
**-f** **-f**
: Specify the starting search directory for "Play from File" mode : Specify the starting search directory for "Play from File" mode

View File

@ -143,7 +143,7 @@ get_dl_dir() {
# sets the video quality # sets the video quality
set_video_quality() { set_video_quality() {
((IS_MP4)) && qualities="best|1080p|720p|480p|360p|worst" || qualities="best|worst" qualities="best|worst"
prompt "Choose quality [$qualities]" prompt "Choose quality [$qualities]"
read -r quality read -r quality
while [[ ! "$quality" =~ ($qualities) ]]; do while [[ ! "$quality" =~ ($qualities) ]]; do
@ -152,6 +152,20 @@ set_video_quality() {
read -r quality read -r quality
done done
[ -z "$quality" ] && die "No quality selected" [ -z "$quality" ] && die "No quality selected"
NEW_QUALITY=1
}
# gets the video quality from the user
get_quality() {
qualities="best|worst"
prompt "Choose quality " "[$qualities]"
read -r quality
while [[ ! "$quality" =~ ($qualities) ]]; do
lg "$quality not a valid quality -> [$qualities]"
prompt "Choose quality " "[$qualities]"
read -r quality
done
lg "selected quality: $quality"
} }
# vim :ft=sh # vim :ft=sh

View File

@ -192,7 +192,7 @@ get_dl_dir() {
# sets the video quality # sets the video quality
set_video_quality() { set_video_quality() {
((IS_MP4)) && qualities="1. best|2. 1080p|3. 720p|4. 480p|5. 360p|6. worst" || qualities="1. best|2. worst" qualities="1. best|2. worst"
while IFS='|' read -ra quals; do while IFS='|' read -ra quals; do
for q in "${quals[@]}"; do for q in "${quals[@]}"; do
if [[ "$(awk '{ print $NF }' <<< "$q")" == "$quality" ]]; then if [[ "$(awk '{ print $NF }' <<< "$q")" == "$quality" ]]; then
@ -206,6 +206,7 @@ set_video_quality() {
-i -l 6 -no-custom -sep '|' -a "$cur_quality" -mesg "$(generate_span "Current quality: $quality")" \ -i -l 6 -no-custom -sep '|' -a "$cur_quality" -mesg "$(generate_span "Current quality: $quality")" \
-p "Choose quality:" -window-title 'aniwrapper' -selected-row "$cur_quality" <<< "$qualities") -p "Choose quality:" -window-title 'aniwrapper' -selected-row "$cur_quality" <<< "$qualities")
quality=$(awk '{ print $2 }' <<< "$choice") quality=$(awk '{ print $2 }' <<< "$choice")
NEW_QUALITY=1
} }
# vim :ft=sh # vim :ft=sh