mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-11-22 03:19:53 -08:00
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:
parent
da45bf15fe
commit
fd954e7ede
32
README.md
32
README.md
@ -145,6 +145,7 @@ aniwrapper -c # Use ani-cli command-line mode (rofi disabled)
|
||||
aniwrapper -C # Connect to history database
|
||||
aniwrapper -d # Download anime in command-line mode
|
||||
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 -h # Show help menu
|
||||
aniwrapper -p # Enable player selection menu
|
||||
@ -262,37 +263,6 @@ Change aniwrapper theme
|
||||
|
||||
</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
|
||||
|
||||
<div align="center">
|
||||
|
62
ani-cli
62
ani-cli
@ -12,10 +12,12 @@ ROFI_THEME="aniwrapper.rasi"
|
||||
THEMES="alter|aniwrapper|dracula|doomone|fancy|material|monokai|nord|nord2|onedark"
|
||||
TMPDIR="${XDG_CACHE_HOME:-$HOME/.cache}/aniwrapper-temp"
|
||||
DPI=96
|
||||
GET_QUALITY=0
|
||||
IS_ROFI=1
|
||||
VERBOSE=0
|
||||
SILENT=0
|
||||
FIRST_EP_NUMBER=1
|
||||
NEW_QUALITY=0
|
||||
PLAYER_FN="mpv"
|
||||
PID=0
|
||||
|
||||
@ -182,8 +184,14 @@ get_video_link() {
|
||||
: $((i += 1))
|
||||
done
|
||||
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"
|
||||
else
|
||||
lg "Using mp4 link"
|
||||
((GET_QUALITY && !NEW_QUALITY)) && set_video_quality
|
||||
video_url=$(get_video_quality_mp4 "$result_links")
|
||||
fi
|
||||
unset result_links
|
||||
@ -223,6 +231,7 @@ process_search() {
|
||||
|
||||
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')
|
||||
lg "Select Episode Result: $select_ep_result"
|
||||
FIRST_EP_NUMBER=1
|
||||
[ -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"
|
||||
@ -299,6 +308,24 @@ open_episode() {
|
||||
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() {
|
||||
lg "Running stream()"
|
||||
if [ "$#" -eq 0 ]; then
|
||||
@ -322,21 +349,18 @@ stream() {
|
||||
die "No anime selection found"
|
||||
fi
|
||||
fi
|
||||
if (((FIRST_EP_NUMBER == LAST_EP_NUMBER && (FIRST_EP_NUMBER == 0 || FIRST_EP_NUMBER == 1)))); then
|
||||
ep_choice_start=1
|
||||
else
|
||||
episode_selection
|
||||
fi
|
||||
get_episode
|
||||
}
|
||||
|
||||
parse_args() {
|
||||
download_dir="."
|
||||
scrape=query
|
||||
quality=best
|
||||
is_select_episodes=1
|
||||
is_download=0
|
||||
is_resume=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
|
||||
a)
|
||||
is_autoplay=1
|
||||
@ -346,6 +370,11 @@ parse_args() {
|
||||
download_dir="$OPTARG"
|
||||
lg "DOWNLOAD DIR: $download_dir"
|
||||
;;
|
||||
e)
|
||||
episodes="$OPTARG"
|
||||
[[ "$episodes" =~ ^[0-9]+(-[0-9]+)? ]] || die "Invalid episode range: $episodes"
|
||||
is_select_episodes=0
|
||||
;;
|
||||
r)
|
||||
is_resume=1
|
||||
;;
|
||||
@ -362,8 +391,7 @@ parse_args() {
|
||||
VERBOSE=1
|
||||
;;
|
||||
q)
|
||||
quality="$OPTARG"
|
||||
lg "passed in quality: $quality"
|
||||
GET_QUALITY=1
|
||||
;;
|
||||
c)
|
||||
IS_ROFI=0
|
||||
@ -461,7 +489,7 @@ show_menu() {
|
||||
;;
|
||||
|
||||
s)
|
||||
episode_selection
|
||||
get_episode
|
||||
episode=$ep_choice_start
|
||||
;;
|
||||
|
||||
@ -489,7 +517,8 @@ show_menu() {
|
||||
is_download=1
|
||||
;;
|
||||
q)
|
||||
break
|
||||
lg "Exiting..."
|
||||
exit 0
|
||||
;;
|
||||
|
||||
*)
|
||||
@ -577,7 +606,7 @@ main() {
|
||||
anime_name="${updated_episode%%/*}"
|
||||
lg "ANIME NAME: $anime_name"
|
||||
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"
|
||||
if [[ "$(run_stmt "$stmt")" -ne 0 ]]; then
|
||||
lg "$updated_episode watched before... adding to watched list"
|
||||
@ -593,11 +622,9 @@ main() {
|
||||
die "No selection made"
|
||||
fi
|
||||
lg "SELECTION: $selection"
|
||||
# get everything before -episode-
|
||||
selection_id="${selection%%/*}"
|
||||
# get everything after -episode-
|
||||
ep_choice_start="${selection##*/ep}"
|
||||
episode_list "$selection_id"
|
||||
get_episode
|
||||
;;
|
||||
esac
|
||||
|
||||
@ -605,13 +632,14 @@ main() {
|
||||
|
||||
for ep in $episodes; do
|
||||
open_episode "$selection_id" "$ep" "$download_dir"
|
||||
sleep 2
|
||||
wait
|
||||
((is_download)) && sleep 2
|
||||
done
|
||||
|
||||
if ((is_download)); then
|
||||
lg "Finished downloading episodes: $episodes for $selection_id... exiting"
|
||||
notification "Finished downloading episodes: $episodes for $selection_id... exiting"
|
||||
exit 0
|
||||
elif ((!is_autoplay)); then
|
||||
elif ((!is_autoplay && is_select_episodes)); then
|
||||
show_menu
|
||||
fi
|
||||
}
|
||||
|
26
aniwrapper
26
aniwrapper
@ -8,7 +8,7 @@ CFG_FILE="$CFG_DIR/themes/aniwrapper.rasi"
|
||||
DEFAULT_DOWNLOAD="$HOME/Videos/sauce"
|
||||
ROFI_THEME="aniwrapper.rasi"
|
||||
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"
|
||||
QUALITY=best
|
||||
PLAYER_FN=mpv
|
||||
@ -22,6 +22,7 @@ IS_ROFI=1
|
||||
IS_SYNC=0
|
||||
IS_ALTERNATE_PLAYER=0
|
||||
IS_VERBOSE=0
|
||||
IS_SELECT_EPISODE=1
|
||||
SELECT_PROVIDER=0
|
||||
SILENT=0
|
||||
|
||||
@ -34,9 +35,9 @@ help_text() {
|
||||
printf "%s\n" "$line"
|
||||
done <<< "
|
||||
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 -c [-dhpqSv] [<query>]
|
||||
aniwrapper -c [-dehpqSv] [<query>]
|
||||
aniwrapper -Q <query>
|
||||
aniwrapper -C
|
||||
Options:
|
||||
@ -44,6 +45,7 @@ Options:
|
||||
-c enable command-line mode (rofi disabled)
|
||||
-C connect to history database
|
||||
-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
|
||||
-h show this help text
|
||||
-p enable player selection menu
|
||||
@ -85,9 +87,6 @@ quit() {
|
||||
}
|
||||
|
||||
run() {
|
||||
if ((!IS_PLAY_FROM_FILE && !IS_SYNC && GET_QUALITY)); then
|
||||
get_quality
|
||||
fi
|
||||
if ((IS_CUSTOM_THEME)); then
|
||||
args+=(-T"$CFG_FILE")
|
||||
elif ((!IS_CUSTOM_THEME)); then
|
||||
@ -106,7 +105,7 @@ get_quality() {
|
||||
-sep '|' -no-custom <<< "$QUALITIES")
|
||||
QUALITY=$(awk '{print $2}' <<< "$selection")
|
||||
else
|
||||
qualities="best|1080p|720p|480p|360p|worst"
|
||||
qualities="best|worst"
|
||||
prompt "Choose quality " "[$qualities]"
|
||||
read -r QUALITY
|
||||
while [[ ! "$QUALITY" =~ ($qualities) ]]; do
|
||||
@ -157,7 +156,7 @@ set_theme() {
|
||||
}
|
||||
|
||||
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
|
||||
a)
|
||||
IS_AUTOPLAY=1
|
||||
@ -178,6 +177,11 @@ parse_args() {
|
||||
D)
|
||||
DPI="$OPTARG"
|
||||
;;
|
||||
e)
|
||||
episodes="$OPTARG"
|
||||
[[ "$episodes" =~ ^[0-9]+(-[0-9]+)? ]] || die "Invalid episode range: $episodes"
|
||||
IS_SELECT_EPISODE=0
|
||||
;;
|
||||
f)
|
||||
IS_PLAY_FROM_FILE=1
|
||||
play_path="$OPTARG"
|
||||
@ -342,6 +346,12 @@ check_flags() {
|
||||
if ((IS_VERBOSE)); then
|
||||
args+=(-v)
|
||||
fi
|
||||
if ((GET_QUALITY)); then
|
||||
args+=(-q)
|
||||
fi
|
||||
if ((!IS_SELECT_EPISODE)); then
|
||||
args+=(-e"$episodes")
|
||||
fi
|
||||
|
||||
lg "ARGS: ${args[*]}"
|
||||
if ((IS_AUTOPLAY || IS_DOWNLOAD || !IS_ROFI || IS_RESUME || IS_PLAY_FROM_FILE)); then
|
||||
|
@ -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
|
||||
.\" that render this, and otherwise B font.
|
||||
@ -70,6 +70,9 @@ Connect to the history database
|
||||
\f[B]-d\f[R]
|
||||
Enable downloading anime in command-line mode
|
||||
.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]
|
||||
Specify the starting search directory for \[lq]Play from File\[rq] mode
|
||||
.TP
|
||||
|
@ -44,6 +44,9 @@ Defaults:
|
||||
**-d**
|
||||
: Enable downloading anime in command-line mode
|
||||
|
||||
**-e** _episode_ **or** _begin_episode - end_episode_
|
||||
: Select episode(s) to stream/download
|
||||
|
||||
**-f**
|
||||
: Specify the starting search directory for "Play from File" mode
|
||||
|
||||
|
@ -143,7 +143,7 @@ get_dl_dir() {
|
||||
|
||||
# sets the video quality
|
||||
set_video_quality() {
|
||||
((IS_MP4)) && qualities="best|1080p|720p|480p|360p|worst" || qualities="best|worst"
|
||||
qualities="best|worst"
|
||||
prompt "Choose quality [$qualities]"
|
||||
read -r quality
|
||||
while [[ ! "$quality" =~ ($qualities) ]]; do
|
||||
@ -152,6 +152,20 @@ set_video_quality() {
|
||||
read -r quality
|
||||
done
|
||||
[ -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
|
||||
|
@ -192,7 +192,7 @@ get_dl_dir() {
|
||||
|
||||
# sets the 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
|
||||
for q in "${quals[@]}"; do
|
||||
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")" \
|
||||
-p "Choose quality:" -window-title 'aniwrapper' -selected-row "$cur_quality" <<< "$qualities")
|
||||
quality=$(awk '{ print $2 }' <<< "$choice")
|
||||
NEW_QUALITY=1
|
||||
}
|
||||
|
||||
# vim :ft=sh
|
||||
|
Loading…
Reference in New Issue
Block a user