mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-10-28 04:44:11 -07:00
port over the new ani-cli command-line menu code
This commit is contained in:
parent
7d08c212fa
commit
cdfe2674d7
223
ani-cli
223
ani-cli
@ -11,29 +11,57 @@ DPI=96
|
|||||||
IS_ROFI=1
|
IS_ROFI=1
|
||||||
VERBOSE=0
|
VERBOSE=0
|
||||||
SILENT=0
|
SILENT=0
|
||||||
|
PLAYER_FN="mpv"
|
||||||
player_fn="mpv"
|
|
||||||
playable="\.mp4|\.mkv|\.ts|\.mp3|\.webm"
|
|
||||||
c_red="\033[1;31m"
|
|
||||||
c_green="\033[1;32m"
|
|
||||||
c_yellow="\033[1;33m"
|
|
||||||
c_blue="\033[1;34m"
|
|
||||||
c_magenta="\033[1;35m"
|
|
||||||
c_cyan="\033[1;36m"
|
|
||||||
c_reset="\033[0m"
|
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
((SILENT != 1)) && printf "$c_red%s$c_reset\n" "$*" >&2
|
((SILENT != 1)) && printf "\033[1;31m%s\033[0m\n" "$*" >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# display an error message to stderr (in red)
|
||||||
err() {
|
err() {
|
||||||
((SILENT != 1)) && printf "$c_red%s$c_reset\n" "$*" >&2
|
((SILENT != 1)) && printf "\033[1;31m%s\033[0m\n" "$*" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
# prints passed in args to stdout if $VERBOSE is set to 1
|
|
||||||
lg() {
|
lg() {
|
||||||
((VERBOSE == 1)) && printf "%s\n" "$*" >&2
|
((VERBOSE == 1)) && printf "\033[1;35m%s\033[0m\n" "$*" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
# display an informational message (first argument in green, second in magenta)
|
||||||
|
inf() {
|
||||||
|
printf "\033[1;32m%s \033[1;35m%s\033[0m\n" "$1" "$2"
|
||||||
|
}
|
||||||
|
|
||||||
|
# prompts the user with message in $1-2 ($1 in blue, $2 in magenta) and saves the input to the variables in $REPLY and $REPLY2
|
||||||
|
prompt() {
|
||||||
|
printf "\033[1;34m%s\033[1;35m%s\033[1;34m: \033[0m" "$1" "$2"
|
||||||
|
}
|
||||||
|
|
||||||
|
# displays an even (cyan) line of a menu line with $2 as an indicator in [] and $1 as the option
|
||||||
|
menu_line_even() {
|
||||||
|
printf "\033[1;34m[\033[1;36m%s\033[1;34m] \033[1;36m%s\033[0m\n" "$2" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# displays an odd (yellow) line of a menu line with $2 as an indicator in [] and $1 as the option
|
||||||
|
menu_line_odd() {
|
||||||
|
printf "\033[1;34m[\033[1;33m%s\033[1;34m] \033[1;33m%s\033[0m\n" "$2" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
menu_line_alternate() {
|
||||||
|
menu_line_parity=${menu_line_parity:-0}
|
||||||
|
|
||||||
|
if [ "$menu_line_parity" -eq 0 ]; then
|
||||||
|
menu_line_odd "$1" "$2"
|
||||||
|
menu_line_parity=1
|
||||||
|
else
|
||||||
|
menu_line_even "$1" "$2"
|
||||||
|
menu_line_parity=0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# displays a warning (red) line of a menu line with $2 as an indicator in [] and $1 as the option
|
||||||
|
menu_line_strong() {
|
||||||
|
printf "\033[1;34m[\033[1;31m%s\033[1;34m] \033[1;31m%s\033[0m\n" "$2" "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
check_input() {
|
check_input() {
|
||||||
@ -124,7 +152,7 @@ notification() {
|
|||||||
if command -v "notify-send" > /dev/null; then
|
if command -v "notify-send" > /dev/null; then
|
||||||
notify-send -i "$ANIWRAPPER_ICON_PATH" "$msg"
|
notify-send -i "$ANIWRAPPER_ICON_PATH" "$msg"
|
||||||
else
|
else
|
||||||
lg "$msg"
|
inf "$msg"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,15 +207,12 @@ update_date() {
|
|||||||
stmt=""
|
stmt=""
|
||||||
case "$1" in
|
case "$1" in
|
||||||
directory)
|
directory)
|
||||||
lg "UPDATING FILE_HISTORY for with directory: directory='$2', filename='DIRECTORY', search_date='$datetime'"
|
|
||||||
stmt="UPDATE file_history SET watch_date = '$datetime' WHERE directory = '$2' and filename = '$3';"
|
stmt="UPDATE file_history SET watch_date = '$datetime' WHERE directory = '$2' and filename = '$3';"
|
||||||
;;
|
;;
|
||||||
file)
|
file)
|
||||||
lg "UPDATING FILE_HISTORY: directory='$2', filename='$3', watch_date='$datetime'"
|
|
||||||
stmt="UPDATE file_history SET watch_date = '$datetime' WHERE directory = '$2' and filename = '$3';"
|
stmt="UPDATE file_history SET watch_date = '$datetime' WHERE directory = '$2' and filename = '$3';"
|
||||||
;;
|
;;
|
||||||
search)
|
search)
|
||||||
lg "UPDATING SEARCH_HISTORY: anime_name='$2', search_date='$datetime'"
|
|
||||||
stmt="UPDATE search_history SET search_date = '$datetime' WHERE anime_name = '$2';"
|
stmt="UPDATE search_history SET search_date = '$datetime' WHERE anime_name = '$2';"
|
||||||
;;
|
;;
|
||||||
sync)
|
sync)
|
||||||
@ -195,20 +220,18 @@ update_date() {
|
|||||||
[ -z "$temp_dt" ] && return 1
|
[ -z "$temp_dt" ] && return 1
|
||||||
hist_dt=$(run_stmt "SELECT watch_date FROM watch_history WHERE anime_name='$2' AND episode_number='$3';")
|
hist_dt=$(run_stmt "SELECT watch_date FROM watch_history WHERE anime_name='$2' AND episode_number='$3';")
|
||||||
hist_dt="${hist_dt// /:}"
|
hist_dt="${hist_dt// /:}"
|
||||||
lg "Checking if update is needed..."
|
|
||||||
if ! check_date "$hist_dt" "$temp_dt"; then
|
if ! check_date "$hist_dt" "$temp_dt"; then
|
||||||
lg "Passed in date is older or same than current date... doing nothing"
|
lg "Passed in date is older or same than current date... doing nothing"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
lg "UPDATING WATCH_HISTORY from sync. watch_date -> $temp_dt"
|
|
||||||
stmt="UPDATE watch_history SET watch_date = '$temp_dt' WHERE anime_name = '$2' AND episode_number = $3;"
|
stmt="UPDATE watch_history SET watch_date = '$temp_dt' WHERE anime_name = '$2' AND episode_number = $3;"
|
||||||
;;
|
;;
|
||||||
watch)
|
watch)
|
||||||
lg "UPDATING WATCH_HISTORY: anime_name='$2', episode_number='$3' watch_date='$datetime'"
|
|
||||||
stmt="UPDATE watch_history SET watch_date = '$datetime' WHERE anime_name = '$2' AND episode_number = $3;"
|
stmt="UPDATE watch_history SET watch_date = '$datetime' WHERE anime_name = '$2' AND episode_number = $3;"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
wait # in case there's another insert/update still running in background?
|
wait # in case there's another insert/update still running in background?
|
||||||
|
lg "UPDATE STMT -> $stmt"
|
||||||
run_stmt "$stmt"
|
run_stmt "$stmt"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,29 +314,29 @@ sync_watch_history() {
|
|||||||
### Play from file###
|
### Play from file###
|
||||||
#####################
|
#####################
|
||||||
|
|
||||||
# opens the passed in file with $player_fn
|
# opens the passed in file with $PLAYER_FN
|
||||||
play_file() {
|
play_file() {
|
||||||
lg "Checking if file is playable"
|
lg "Checking if file is playable"
|
||||||
if [[ "$1" =~ ($playable)$ ]]; then
|
if [[ "$1" =~ (\.mp4|\.mkv|\.ts|\.mp3|\.webm)$ ]]; then
|
||||||
filename="${1##*/}"
|
filename="${1##*/}"
|
||||||
directory="${1%/*}"
|
directory="${1%/*}"
|
||||||
insert_history "file" "$directory" "$filename" &
|
insert_history "file" "$directory" "$filename" &
|
||||||
if [[ "$1" =~ .mp3 ]]; then
|
if [[ "$1" =~ .mp3 ]]; then
|
||||||
notification "Playing $1"
|
notification "Playing $1"
|
||||||
case "$player_fn" in
|
case "$PLAYER_FN" in
|
||||||
mpv)
|
mpv)
|
||||||
nohup "$player_fn" --no-video "$1" > /dev/null 2>&1
|
nohup "$PLAYER_FN" --no-video "$1" > /dev/null 2>&1
|
||||||
;;
|
;;
|
||||||
mplayer)
|
mplayer)
|
||||||
nohup "$player_fn" -novideo "$1" > /dev/null 2>&1
|
nohup "$PLAYER_FN" -novideo "$1" > /dev/null 2>&1
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
nohup "$player_fn" "$1" > /dev/null 2>&1
|
nohup "$PLAYER_FN" "$1" > /dev/null 2>&1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
notification "Playing $1"
|
notification "Playing $1"
|
||||||
nohup "$player_fn" "$1" > /dev/null 2>&1 &
|
nohup "$PLAYER_FN" "$1" > /dev/null 2>&1 &
|
||||||
fi
|
fi
|
||||||
return $?
|
return $?
|
||||||
else
|
else
|
||||||
@ -423,16 +446,14 @@ get_search_query() {
|
|||||||
-mesg "$(generate_span "$msg")" \
|
-mesg "$(generate_span "$msg")" \
|
||||||
-config "$ROFI_CFG" < <(run_stmt "$stmt"))
|
-config "$ROFI_CFG" < <(run_stmt "$stmt"))
|
||||||
query="${query//[1-9]*\. /}"
|
query="${query//[1-9]*\. /}"
|
||||||
lg "Query: $query"
|
|
||||||
elif [ "$IS_ROFI" -eq 0 ]; then
|
elif [ "$IS_ROFI" -eq 0 ]; then
|
||||||
printf "Search Anime: "
|
prompt "Search Anime"
|
||||||
read -r query
|
read -r query
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# get anime name along with its id
|
# get anime name along with its id
|
||||||
search_anime() {
|
search_anime() {
|
||||||
lg "NUM ARGS: $#"
|
|
||||||
if [[ $# -gt 1 ]]; then
|
if [[ $# -gt 1 ]]; then
|
||||||
# if multi-word query, concatenate into one string and replace spaces with '-'
|
# if multi-word query, concatenate into one string and replace spaces with '-'
|
||||||
search="$*"
|
search="$*"
|
||||||
@ -473,9 +494,7 @@ anime_selection() {
|
|||||||
while read -r anime_id; do
|
while read -r anime_id; do
|
||||||
menu+="$((cnt + 1)). $anime_id\n"
|
menu+="$((cnt + 1)). $anime_id\n"
|
||||||
res["$cnt"]="$anime_id"
|
res["$cnt"]="$anime_id"
|
||||||
lg "ANIME: $anime_id"
|
|
||||||
if ! check_db "search" "$anime_id"; then
|
if ! check_db "search" "$anime_id"; then
|
||||||
lg "$anime_id HAS BEEN SEARCHED BEFORE"
|
|
||||||
[ -z "$searched" ] && searched="$cnt" || searched="$searched, $cnt"
|
[ -z "$searched" ] && searched="$cnt" || searched="$searched, $cnt"
|
||||||
fi
|
fi
|
||||||
((++cnt))
|
((++cnt))
|
||||||
@ -484,8 +503,6 @@ anime_selection() {
|
|||||||
EOF
|
EOF
|
||||||
menu+="$((++cnt)). Quit"
|
menu+="$((++cnt)). Quit"
|
||||||
|
|
||||||
lg "searched indexes: $searched"
|
|
||||||
|
|
||||||
# get the anime from indexed list
|
# get the anime from indexed list
|
||||||
msg="$(generate_span "Query: $query")"
|
msg="$(generate_span "Query: $query")"
|
||||||
user_input=$(printf "${menu[@]}" |
|
user_input=$(printf "${menu[@]}" |
|
||||||
@ -496,7 +513,6 @@ anime_selection() {
|
|||||||
-mesg "$msg" -only-match)
|
-mesg "$msg" -only-match)
|
||||||
[ -z "$user_input" ] && return 1
|
[ -z "$user_input" ] && return 1
|
||||||
if [ "$(awk '{ print $NF }' <<< "$user_input")" = "Quit" ]; then
|
if [ "$(awk '{ print $NF }' <<< "$user_input")" = "Quit" ]; then
|
||||||
lg "QUITTING"
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -504,22 +520,13 @@ anime_selection() {
|
|||||||
choice="${choice::-1}" # Remove period after number
|
choice="${choice::-1}" # Remove period after number
|
||||||
name=$(printf '%s\n' "$user_input" | awk '{print $NF}')
|
name=$(printf '%s\n' "$user_input" | awk '{print $NF}')
|
||||||
else
|
else
|
||||||
menu_format_string='[%d] %s\n'
|
|
||||||
menu_format_string_c1="$c_blue[$c_cyan%d$c_blue] $c_reset%s\n"
|
|
||||||
menu_format_string_c2="$c_blue[$c_cyan%d$c_blue] $c_yellow%s$c_reset\n"
|
|
||||||
count=1
|
count=1
|
||||||
while read -r anime_id; do
|
while read -r anime_id; do
|
||||||
# alternating colors for menu
|
menu_line_alternate "$anime_id" "$count"
|
||||||
[ $((count % 2)) -eq 0 ] &&
|
: count=$((count += 1))
|
||||||
menu_format_string=$menu_format_string_c1 ||
|
|
||||||
menu_format_string=$menu_format_string_c2
|
|
||||||
|
|
||||||
printf "$menu_format_string" "$count" "$anime_id"
|
|
||||||
count=$((count + 1))
|
|
||||||
done <<< "$search_results"
|
done <<< "$search_results"
|
||||||
printf "$c_blue%s$c_green" "Enter number: "
|
prompt "Enter choice: "
|
||||||
read choice
|
read -r choice
|
||||||
printf "$c_reset"
|
|
||||||
name="$anime_id"
|
name="$anime_id"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -533,23 +540,19 @@ anime_selection() {
|
|||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
count=$((count + 1))
|
count=$((count + 1))
|
||||||
done <<- EOF
|
done <<< "$search_results"
|
||||||
$search_results
|
|
||||||
EOF
|
|
||||||
|
|
||||||
printf "$c_reset"
|
|
||||||
[ -z "$name" ] && name="$anime_id"
|
|
||||||
[ -z "$selection_id" ] && die "Invalid number entered"
|
[ -z "$selection_id" ] && die "Invalid number entered"
|
||||||
|
[ -z "$name" ] && name="$anime_id"
|
||||||
insert_history "search" "$name" &
|
insert_history "search" "$name" &
|
||||||
|
|
||||||
read -r last_ep_number <<- EOF
|
read -r last_ep_number < <(search_eps "$selection_id")
|
||||||
$(search_eps "$selection_id")
|
|
||||||
EOF
|
|
||||||
}
|
}
|
||||||
|
|
||||||
episode_selection() {
|
episode_selection() {
|
||||||
ep_choice_start="1"
|
ep_choice_start=1 first_ep_number=0
|
||||||
|
result=$(get_dpage_link "$anime_id" "$first_ep_number")
|
||||||
|
[ -z "$result" ] && first_ep_number=1
|
||||||
if [ "$IS_ROFI" -eq 1 ]; then
|
if [ "$IS_ROFI" -eq 1 ]; then
|
||||||
lg "Anime ID: $anime_id"
|
lg "Anime ID: $anime_id"
|
||||||
stmt="SELECT DISTINCT episode_number FROM watch_history WHERE anime_name = '$anime_id';"
|
stmt="SELECT DISTINCT episode_number FROM watch_history WHERE anime_name = '$anime_id';"
|
||||||
@ -570,24 +573,25 @@ episode_selection() {
|
|||||||
msg2="Range of episodes can be provided as: START_EPISODE - END_EPISODE"
|
msg2="Range of episodes can be provided as: START_EPISODE - END_EPISODE"
|
||||||
[ "$is_download" -eq 1 ] && msg=$(printf "%s\n%s" "$(generate_span "$msg1")" "$(generate_span "$msg2")") || msg=$(printf "%s\n" "$(generate_span "$msg1")")
|
[ "$is_download" -eq 1 ] && msg=$(printf "%s\n%s" "$(generate_span "$msg1")" "$(generate_span "$msg2")") || msg=$(printf "%s\n" "$(generate_span "$msg1")")
|
||||||
choice=$(
|
choice=$(
|
||||||
seq 1 "$last_ep_number" |
|
seq "$first_ep_number" "$last_ep_number" |
|
||||||
rofi -dpi "$DPI" -dmenu -l 12 \
|
rofi -dpi "$DPI" -dmenu -l 12 \
|
||||||
-theme-str 'window {width: 45%;}' \
|
-theme-str 'window {width: 45%;}' \
|
||||||
-a "$watch_history" \
|
-a "$watch_history" \
|
||||||
-p "Select Episode [1, $last_ep_number]:" \
|
-p "Select Episode [$first_ep_number, $last_ep_number]:" \
|
||||||
-mesg "$msg" \
|
-mesg "$msg" \
|
||||||
-config "$ROFI_CFG"
|
-config "$ROFI_CFG"
|
||||||
)
|
)
|
||||||
ep_choice_start=$(printf '%s\n' "${choice}" | awk '{print $1}')
|
ep_choice_start=$(printf '%s\n' "${choice}" | awk '{print $1}')
|
||||||
ep_choice_end=$(printf '%s\n' "${choice}" | awk '{print $NF}')
|
ep_choice_end=$(printf '%s\n' "${choice}" | awk '{print $NF}')
|
||||||
lg "START: $ep_choice_start | END: $ep_choice_end"
|
lg "START: $ep_choice_start | END: $ep_choice_end"
|
||||||
elif [ $last_ep_number -gt 1 ]; then
|
elif [ "$last_ep_number" -gt 1 ]; then
|
||||||
[ $is_download -eq 1 ] &&
|
[ "$is_download" -eq 1 ] &&
|
||||||
printf "Range of episodes can be specified: start_number end_number\n"
|
inf "Range of episodes can be specified: start_number end_number"
|
||||||
|
|
||||||
printf "${c_blue}Choose episode $c_cyan[1-%d]$c_reset:$c_green " $last_ep_number
|
# printf "${c_blue}Choose episode $c_cyan[1-%d]$c_reset:$c_green " $last_ep_number
|
||||||
read ep_choice_start ep_choice_end
|
prompt "Choose episode " "[$first_ep_number-$last_ep_number]"
|
||||||
printf "$c_reset"
|
read -r ep_choice_start ep_choice_end
|
||||||
|
[ -z "$ep_choice_end" ] && ep_choice_end="$ep_choice_start"
|
||||||
fi
|
fi
|
||||||
if [ "$(echo "$ep_choice_start" | awk '{ printf substr($0, 1, 1) }')" = "h" ]; then
|
if [ "$(echo "$ep_choice_start" | awk '{ printf substr($0, 1, 1) }')" = "h" ]; then
|
||||||
lg "IS A HALF EPISODE"
|
lg "IS A HALF EPISODE"
|
||||||
@ -603,7 +607,6 @@ episode_selection() {
|
|||||||
if [[ "$ep_choice_start" -eq "$ep_choice_end" ]]; then
|
if [[ "$ep_choice_start" -eq "$ep_choice_end" ]]; then
|
||||||
ep_choice_end=""
|
ep_choice_end=""
|
||||||
fi
|
fi
|
||||||
printf "$c_reset"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open_episode() {
|
open_episode() {
|
||||||
@ -616,15 +619,15 @@ open_episode() {
|
|||||||
episode=$episode"-5"
|
episode=$episode"-5"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
lg "Getting data for episode $episode"
|
|
||||||
|
|
||||||
# Don't update watch history if downloading episode
|
# Don't update watch history if downloading episode
|
||||||
if [ "$is_download" -eq 0 ]; then
|
(("$is_download" == 0)) && insert_history "watch" "$anime_id" "$episode" &
|
||||||
insert_history "watch" "$anime_id" "$episode" &
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
lg "Getting data for episode $episode"
|
||||||
dpage_link=$(get_dpage_link "$anime_id" "$episode")
|
dpage_link=$(get_dpage_link "$anime_id" "$episode")
|
||||||
video_url=$(get_video_quality "$dpage_link")
|
video_url=$(get_video_quality "$dpage_link")
|
||||||
|
if [ -z "$video_url" ]; then
|
||||||
|
die "Video URL not found"
|
||||||
|
fi
|
||||||
lg "Download link: $dpage_link"
|
lg "Download link: $dpage_link"
|
||||||
lg "Video url: $video_url"
|
lg "Video url: $video_url"
|
||||||
|
|
||||||
@ -633,38 +636,32 @@ open_episode() {
|
|||||||
half_ep=0
|
half_ep=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$video_url" ]; then
|
|
||||||
die "Video URL not found"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$is_download" -eq 0 ]; then
|
if [ "$is_download" -eq 0 ]; then
|
||||||
kill "$PID" > /dev/null 2>&1
|
kill "$PID" > /dev/null 2>&1
|
||||||
case "$player_fn" in
|
case "$PLAYER_FN" in
|
||||||
mpv)
|
mpv)
|
||||||
nohup "$player_fn" --referrer="$dpage_link" "$video_url" > /dev/null 2>&1 &
|
nohup "$PLAYER_FN" --referrer="$dpage_link" "$video_url" > /dev/null 2>&1 &
|
||||||
;;
|
;;
|
||||||
mplayer)
|
mplayer)
|
||||||
nohup "$player_fn" -referrer "$dpage_link" "$video_url" > /dev/null 2>&1 &
|
nohup "$PLAYER_FN" -referrer "$dpage_link" "$video_url" > /dev/null 2>&1 &
|
||||||
;;
|
;;
|
||||||
vlc)
|
vlc)
|
||||||
nohup "$player_fn" --play-and-exit --http-referrer="$dpage_link" "$video_url" > /dev/null 2>&1 &
|
nohup "$PLAYER_FN" --play-and-exit --http-referrer="$dpage_link" "$video_url" > /dev/null 2>&1 &
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
# try to open with just the video url
|
nohup "$PLAYER_FN" "$video_url" > /dev/null 2>&1 & # try to open with just the video url
|
||||||
nohup "$player_fn" "$video_url" > /dev/null 2>&1 &
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
PID=$!
|
PID=$!
|
||||||
if command -v "notify-send" > /dev/null; then
|
if command -v "notify-send" > /dev/null; then
|
||||||
((SILENT != 1)) && notify-send -i "$ANIWRAPPER_ICON_PATH" "Playing $anime_id - Episode $episode"
|
((SILENT != 1)) && notify-send -i "$ANIWRAPPER_ICON_PATH" "Playing $anime_id - Episode $episode"
|
||||||
else
|
else
|
||||||
((SILENT != 1)) && printf "${c_green}\nVideo playing"
|
((SILENT != 1)) && inf "Playing $anime_id - Episode $episode"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
lg "Downloading episode $episode ..."
|
lg "Downloading episode $episode ..."
|
||||||
dl_dir="${ddir// /}/$anime_id"
|
dl_dir="${ddir// /}/$anime_id"
|
||||||
# add 0 padding to the episode name
|
episode=$(printf "%03d" "$episode") # add 0 padding to the episode name
|
||||||
episode=$(printf "%03d" "$episode")
|
|
||||||
{
|
{
|
||||||
mkdir -p "$dl_dir" || die "Could not create directory"
|
mkdir -p "$dl_dir" || die "Could not create directory"
|
||||||
if command -v "notify-send" > /dev/null; then
|
if command -v "notify-send" > /dev/null; then
|
||||||
@ -704,17 +701,15 @@ stream() {
|
|||||||
die "No anime selection found"
|
die "No anime selection found"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# skip search_anime function and assign $query if previously searched
|
|
||||||
selection_id="$anime_id"
|
selection_id="$anime_id"
|
||||||
insert_history "search" "$anime_id" &
|
insert_history "search" "$anime_id" &
|
||||||
read -r last_ep_number < <(search_eps "$anime_id")
|
read -r last_ep_number < <(search_eps "$anime_id")
|
||||||
fi
|
fi
|
||||||
|
lg "LAST EP NUMBER -> $last_ep_number"
|
||||||
episode_selection
|
episode_selection
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_args() {
|
parse_args() {
|
||||||
# to clear the colors when exited using SIGINT
|
|
||||||
trap "printf '$c_reset'" INT HUP
|
|
||||||
scrape=query
|
scrape=query
|
||||||
quality=best
|
quality=best
|
||||||
is_download=0
|
is_download=0
|
||||||
@ -809,13 +804,13 @@ parse_args() {
|
|||||||
SILENT=1
|
SILENT=1
|
||||||
;;
|
;;
|
||||||
p)
|
p)
|
||||||
player_fn="$OPTARG"
|
PLAYER_FN="$OPTARG"
|
||||||
if ! command -v "$player_fn" > /dev/null; then
|
if ! command -v "$PLAYER_FN" > /dev/null; then
|
||||||
die "ERROR: $player_fn does not exist"
|
die "ERROR: $PLAYER_FN does not exist"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
printf "%s\n" "Invalid option"
|
inf "Invalid option"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -846,20 +841,20 @@ main() {
|
|||||||
lg "Most recently watched episode: $ep_choice_start"
|
lg "Most recently watched episode: $ep_choice_start"
|
||||||
;;
|
;;
|
||||||
sync)
|
sync)
|
||||||
printf "%s" "Enter username for remote user: "
|
prompt "Enter username for remote user: "
|
||||||
read -r username
|
read -r username
|
||||||
printf "%s" "Enter host for remote user: "
|
prompt "Enter host for remote user: "
|
||||||
read -r host
|
read -r host
|
||||||
|
|
||||||
connection_str="$username@$host"
|
connection_str="$username@$host"
|
||||||
printf "%s" "Enter port to connect to remote host with or leave blank for default (22): "
|
prompt "Enter port to connect to remote host with or leave blank for default (22): "
|
||||||
read -r port
|
read -r port
|
||||||
[ -z "$port" ] && PORT=22 || PORT="$port"
|
[ -z "$port" ] && PORT=22 || PORT="$port"
|
||||||
|
|
||||||
printf "%s" "Enter path to private key (leave blank if unsure or not needed): "
|
prompt "Enter path to private key (leave blank if unsure or not needed): "
|
||||||
read -r key_path
|
read -r key_path
|
||||||
|
|
||||||
printf "%s\n" "Syncing database with: $connection_str on port $PORT"
|
lg "Syncing database with: $connection_str on port $PORT"
|
||||||
temp_db="/tmp/aniwrapper_tmp_history.sqlite3"
|
temp_db="/tmp/aniwrapper_tmp_history.sqlite3"
|
||||||
|
|
||||||
if [[ -z "$key_path" ]]; then
|
if [[ -z "$key_path" ]]; then
|
||||||
@ -905,24 +900,22 @@ main() {
|
|||||||
episode=${ep_choice_end:-$ep_choice_start}
|
episode=${ep_choice_end:-$ep_choice_start}
|
||||||
choice=''
|
choice=''
|
||||||
while :; do
|
while :; do
|
||||||
printf "\n${c_green}Currently playing %s episode ${c_cyan}%d/%d\n" "$selection_id" $episode $last_ep_number
|
inf "Currently playing $selection_id episode" "$episode/$last_ep_number"
|
||||||
if [ "$episode" -ne "$last_ep_number" ]; then
|
if ((episode != last_ep_number)); then
|
||||||
printf "$c_blue[${c_cyan}%s$c_blue] $c_yellow%s$c_reset\n" "n" "next episode"
|
menu_line_alternate "next episode" "n"
|
||||||
fi
|
fi
|
||||||
if [ "$episode" -ne "1" ]; then
|
if ((episode != first_ep_number)); then
|
||||||
printf "$c_blue[${c_cyan}%s$c_blue] $c_magenta%s$c_reset\n" "p" "previous episode"
|
menu_line_alternate "previous episode" "p"
|
||||||
fi
|
fi
|
||||||
if [ "$last_ep_number" -ne "1" ]; then
|
if ((first_ep_number != last_ep_number)); then
|
||||||
printf "$c_blue[${c_cyan}%s$c_blue] $c_yellow%s$c_reset\n" "s" "select episode"
|
menu_line_alternate "select episode" "s"
|
||||||
fi
|
fi
|
||||||
printf "$c_blue[${c_cyan}%s$c_blue] $c_magenta%s$c_reset\n" "r" "replay current episode"
|
menu_line_alternate "replay current episode" "r"
|
||||||
printf "$c_blue[${c_cyan}%s$c_blue] $c_yellow%s$c_reset\n" "a" "search for another anime"
|
menu_line_alternate "search for another anime" "a"
|
||||||
printf "$c_blue[${c_cyan}%s$c_blue] $c_magenta%s$c_reset\n" "Q" "change video quality (current: $quality)"
|
menu_line_alternate "select quality (current: $quality)" "Q"
|
||||||
printf "$c_blue[${c_cyan}%s$c_blue] $c_red%s$c_reset\n" "q" "exit"
|
menu_line_strong "exit" "q"
|
||||||
printf "${c_blue}Enter choice:${c_green} "
|
prompt "Enter choice"
|
||||||
read -r choice
|
read -r choice
|
||||||
|
|
||||||
printf "$c_reset"
|
|
||||||
case $choice in
|
case $choice in
|
||||||
n)
|
n)
|
||||||
episode=$((episode + 1))
|
episode=$((episode + 1))
|
||||||
@ -973,11 +966,11 @@ main() {
|
|||||||
quality=$(awk '{ print $2 }' <<< "$choice")
|
quality=$(awk '{ print $2 }' <<< "$choice")
|
||||||
else
|
else
|
||||||
qualities="best|1080p|720p|480p|360p|worst"
|
qualities="best|1080p|720p|480p|360p|worst"
|
||||||
printf "${c_blue}Choose quality: [$qualities]:$c_reset "
|
prompt "Choose quality: [$qualities]"
|
||||||
read -r quality
|
read -r quality
|
||||||
while [[ ! "$quality" =~ ($qualities) ]]; do
|
while [[ ! "$quality" =~ ($qualities) ]]; do
|
||||||
lg "$quality not a valid quality"
|
lg "$quality not a valid quality"
|
||||||
printf "${c_blue}Choose quality: [$qualities]:$c_reset "
|
prompt "Choose quality: [$qualities]"
|
||||||
read -r quality
|
read -r quality
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
@ -997,7 +990,7 @@ main() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
dep_ch "$player_fn" "curl" "sed" "grep" "sqlite3" "rofi" "git" "aria2c"
|
dep_ch "$PLAYER_FN" "curl" "sed" "grep" "sqlite3" "rofi" "git" "aria2c"
|
||||||
parse_args "$@"
|
parse_args "$@"
|
||||||
shift $((OPTIND - 1))
|
shift $((OPTIND - 1))
|
||||||
main "$@"
|
main "$@"
|
||||||
|
21
aniwrapper
21
aniwrapper
@ -65,6 +65,16 @@ lg() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# display an informational message (first argument in green, second in magenta)
|
||||||
|
inf() {
|
||||||
|
printf "\033[1;32m%s \033[1;35m%s\033[0m\n" "$1" "$2"
|
||||||
|
}
|
||||||
|
|
||||||
|
# prompts the user with message in $1-2 ($1 in blue, $2 in magenta) and saves the input to the variables in $REPLY and $REPLY2
|
||||||
|
prompt() {
|
||||||
|
printf "\033[1;34m%s\033[1;35m%s\033[1;34m: \033[0m" "$1" "$2"
|
||||||
|
}
|
||||||
|
|
||||||
seppuku() {
|
seppuku() {
|
||||||
printf "%s\n" "$*"
|
printf "%s\n" "$*"
|
||||||
exit 1
|
exit 1
|
||||||
@ -110,11 +120,11 @@ get_quality() {
|
|||||||
QUALITY=$(awk '{print $2}' <<< "$selection")
|
QUALITY=$(awk '{print $2}' <<< "$selection")
|
||||||
else
|
else
|
||||||
qualities="best|1080p|720p|480p|360p|worst"
|
qualities="best|1080p|720p|480p|360p|worst"
|
||||||
printf "%s" "Choose quality: [$qualities]: "
|
prompt "Choose quality " "[$qualities]"
|
||||||
read -r QUALITY
|
read -r QUALITY
|
||||||
while [[ ! "$QUALITY" =~ ($qualities) ]]; do
|
while [[ ! "$QUALITY" =~ ($qualities) ]]; do
|
||||||
lg "$QUALITY not a valid quality -> [$qualities]"
|
lg "$QUALITY not a valid quality -> [$qualities]"
|
||||||
printf "%s" "Choose quality: [$qualities]: "
|
prompt "Choose quality " "[$qualities]"
|
||||||
read -r QUALITY
|
read -r QUALITY
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
@ -250,7 +260,7 @@ get_player() {
|
|||||||
while IFS='|' read -ra players; do
|
while IFS='|' read -ra players; do
|
||||||
printf "%s\n" "${players[@]}"
|
printf "%s\n" "${players[@]}"
|
||||||
done <<< "$SUPPORTED_PLAYERS"
|
done <<< "$SUPPORTED_PLAYERS"
|
||||||
printf "%s" "Enter player: "
|
prompt "Enter player"
|
||||||
read -r PLAYER_FN
|
read -r PLAYER_FN
|
||||||
fi
|
fi
|
||||||
[ -z "$PLAYER_FN" ] && PLAYER_FN=mpv
|
[ -z "$PLAYER_FN" ] && PLAYER_FN=mpv
|
||||||
@ -272,7 +282,7 @@ check_flags() {
|
|||||||
run -c "$@"
|
run -c "$@"
|
||||||
exit $?
|
exit $?
|
||||||
elif ((IS_ROFI == 0 && IS_DOWNLOAD == 1)); then
|
elif ((IS_ROFI == 0 && IS_DOWNLOAD == 1)); then
|
||||||
printf "%s" "Enter download dir: "
|
prompt "Enter download directory"
|
||||||
read -r dl_dir
|
read -r dl_dir
|
||||||
lg "Download dir: $dl_dir"
|
lg "Download dir: $dl_dir"
|
||||||
if [ ! -d "$dl_dir" ]; then
|
if [ ! -d "$dl_dir" ]; then
|
||||||
@ -298,6 +308,9 @@ get_dl_dir() {
|
|||||||
)
|
)
|
||||||
# if dl_dir is none set to current directory
|
# if dl_dir is none set to current directory
|
||||||
[ "$dl_dir" == "" ] && dl_dir="$DEFAULT_DOWNLOAD"
|
[ "$dl_dir" == "" ] && dl_dir="$DEFAULT_DOWNLOAD"
|
||||||
|
if [ ! -d "$dl_dir" ]; then
|
||||||
|
mkdir -p "$dl_dir" || seppuku "Error creating directory: $dl_dir"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
########
|
########
|
||||||
|
Loading…
Reference in New Issue
Block a user