mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-11-22 03:19:53 -08:00
Compare commits
No commits in common. "b272fc399472ca3a3e4186695a566dd3d41578b4" and "10a675202ad1a159c512308bbd2d0c36da97aebb" have entirely different histories.
b272fc3994
...
10a675202a
251
ani-cli
251
ani-cli
@ -11,63 +11,32 @@ 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 "\033[1;31m%s\033[0m\n" "$*" >&2
|
((SILENT != 1)) && printf "$c_red%s$c_reset\n" "$*" >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# display an error message to stderr (in red)
|
|
||||||
err() {
|
err() {
|
||||||
((SILENT != 1)) && printf "\033[1;31m%s\033[0m\n" "$*" >&2
|
((SILENT != 1)) && printf "$c_red%s$c_reset\n" "$*" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# prints passed in args to stdout if $VERBOSE is set to 1
|
||||||
lg() {
|
lg() {
|
||||||
((VERBOSE == 1)) && printf "\033[1;35m%s\033[0m\n" "$*" >&2
|
((VERBOSE == 1)) && printf "%s\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() {
|
||||||
if [[ -z "$ep_choice_start" ]] && [[ -z "$ep_choice_end" ]]; then
|
|
||||||
die "No episode(s) selected"
|
|
||||||
fi
|
|
||||||
[ "$ep_choice_start" -eq "$ep_choice_start" ] 2> /dev/null || die "Invalid number entered: $ep_choice_start"
|
[ "$ep_choice_start" -eq "$ep_choice_start" ] 2> /dev/null || die "Invalid number entered: $ep_choice_start"
|
||||||
episodes=$ep_choice_start
|
episodes=$ep_choice_start
|
||||||
if [ -n "$ep_choice_end" ]; then
|
if [ -n "$ep_choice_end" ]; then
|
||||||
@ -152,7 +121,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
|
||||||
inf "$msg"
|
lg "$msg"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,12 +176,15 @@ 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)
|
||||||
@ -220,18 +192,20 @@ 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"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,25 +288,30 @@ 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" =~ (\.mp4|\.mkv|\.ts|\.webm)$ ]]; then
|
if [[ "$1" =~ ($playable)$ ]]; then
|
||||||
filename="${1##*/}"
|
filename="${1##*/}"
|
||||||
directory="${1%/*}"
|
directory="${1%/*}"
|
||||||
insert_history "file" "$directory" "$filename" &
|
insert_history "file" "$directory" "$filename" &
|
||||||
notification "Playing $1"
|
if [[ "$1" =~ .mp3 ]]; then
|
||||||
case "$PLAYER_FN" in
|
notification "Playing $1"
|
||||||
mpv)
|
case "$player_fn" in
|
||||||
nohup "$PLAYER_FN" --force-media-title="aniwrapper: play-from-file - $1" "$1" > /dev/null 2>&1 &
|
mpv)
|
||||||
;;
|
nohup "$player_fn" --no-video "$1" > /dev/null 2>&1
|
||||||
mplayer)
|
;;
|
||||||
nohup "$PLAYER_FN" -title "aniwrapper: play-from-file - $1" "$1" > /dev/null 2>&1 &
|
mplayer)
|
||||||
;;
|
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
|
||||||
|
notification "Playing $1"
|
||||||
|
nohup "$player_fn" "$1" > /dev/null 2>&1 &
|
||||||
|
fi
|
||||||
return $?
|
return $?
|
||||||
else
|
else
|
||||||
die "File: $1 is not playable... Quitting"
|
die "File: $1 is not playable... Quitting"
|
||||||
@ -441,14 +420,16 @@ 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
|
||||||
prompt "Search Anime"
|
printf "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="$*"
|
||||||
@ -489,7 +470,9 @@ 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))
|
||||||
@ -498,6 +481,8 @@ 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[@]}" |
|
||||||
@ -508,6 +493,7 @@ 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
|
||||||
|
|
||||||
@ -515,13 +501,22 @@ 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
|
||||||
menu_line_alternate "$anime_id" "$count"
|
# alternating colors for menu
|
||||||
: count=$((count += 1))
|
[ $((count % 2)) -eq 0 ] &&
|
||||||
|
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"
|
||||||
prompt "Enter choice: "
|
printf "$c_blue%s$c_green" "Enter number: "
|
||||||
read -r choice
|
read choice
|
||||||
|
printf "$c_reset"
|
||||||
name="$anime_id"
|
name="$anime_id"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -535,19 +530,23 @@ anime_selection() {
|
|||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
count=$((count + 1))
|
count=$((count + 1))
|
||||||
done <<< "$search_results"
|
done <<- EOF
|
||||||
|
$search_results
|
||||||
|
EOF
|
||||||
|
|
||||||
[ -z "$selection_id" ] && die "Invalid number entered"
|
printf "$c_reset"
|
||||||
[ -z "$name" ] && name="$anime_id"
|
[ -z "$name" ] && name="$anime_id"
|
||||||
|
[ -z "$selection_id" ] && die "Invalid number entered"
|
||||||
|
|
||||||
insert_history "search" "$name" &
|
insert_history "search" "$name" &
|
||||||
|
|
||||||
read -r last_ep_number < <(search_eps "$selection_id")
|
read -r last_ep_number <<- EOF
|
||||||
|
$(search_eps "$selection_id")
|
||||||
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
episode_selection() {
|
episode_selection() {
|
||||||
ep_choice_start=1 first_ep_number=0
|
ep_choice_start="1"
|
||||||
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';"
|
||||||
@ -568,25 +567,24 @@ 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 "$first_ep_number" "$last_ep_number" |
|
seq 1 "$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 [$first_ep_number, $last_ep_number]:" \
|
-p "Select Episode [1, $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 ] &&
|
||||||
inf "Range of episodes can be specified: start_number end_number"
|
printf "Range of episodes can be specified: start_number end_number\n"
|
||||||
|
|
||||||
# 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
|
||||||
prompt "Choose episode " "[$first_ep_number-$last_ep_number]"
|
read ep_choice_start ep_choice_end
|
||||||
read -r ep_choice_start ep_choice_end
|
printf "$c_reset"
|
||||||
[ -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"
|
||||||
@ -594,14 +592,15 @@ episode_selection() {
|
|||||||
ep_choice_start=$(echo "$ep_choice_start" | awk '{ printf substr($0, 2) }')
|
ep_choice_start=$(echo "$ep_choice_start" | awk '{ printf substr($0, 2) }')
|
||||||
ep_choice_end=$ep_choice_start
|
ep_choice_end=$ep_choice_start
|
||||||
fi
|
fi
|
||||||
if (((ep_choice_start <= 0 || ep_choice_start > last_ep_number) || ep_choice_end < ep_choice_start || ep_choice_end > last_ep_number)); then
|
if [[ -z "$ep_choice_start" ]] && [[ -z "$ep_choice_end" ]]; then
|
||||||
die "Invalid episode/range entered: ep_start -> $ep_choice_start | ep_end -> $ep_choice_end"
|
die "No episode range entered"
|
||||||
fi
|
fi
|
||||||
# if only one episode was entered, set ep_choice_end to empty string so only selected episode plays
|
# if only one episode was entered, set ep_choice_end to empty string so only selected episode plays
|
||||||
# otherwise plays from ep 1 - ep_choice_start
|
# otherwise plays from ep 1 - ep_choice_start
|
||||||
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() {
|
||||||
@ -614,15 +613,15 @@ open_episode() {
|
|||||||
episode=$episode"-5"
|
episode=$episode"-5"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Don't update watch history if downloading episode
|
|
||||||
(("$is_download" == 0)) && insert_history "watch" "$anime_id" "$episode" &
|
|
||||||
|
|
||||||
lg "Getting data for episode $episode"
|
lg "Getting data for episode $episode"
|
||||||
|
|
||||||
|
# Don't update watch history if downloading episode
|
||||||
|
if [ "$is_download" -eq 0 ]; then
|
||||||
|
insert_history "watch" "$anime_id" "$episode" &
|
||||||
|
fi
|
||||||
|
|
||||||
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"
|
||||||
|
|
||||||
@ -631,32 +630,38 @@ 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" --force-media-title="aniwrapper: $anime_id E$(printf "%03d" "$episode")" > /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" -title "aniwrapper: $anime_id E$(printf "%03d" "$episode")" > /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 &
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
nohup "$PLAYER_FN" "$video_url" > /dev/null 2>&1 & # try to open with just the video url
|
# 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)) && inf "Playing $anime_id - Episode $episode"
|
((SILENT != 1)) && printf "${c_green}\nVideo playing"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
lg "Downloading episode $episode ..."
|
lg "Downloading episode $episode ..."
|
||||||
dl_dir="${ddir// /}/$anime_id"
|
dl_dir="${ddir// /}/$anime_id"
|
||||||
episode=$(printf "%03d" "$episode") # add 0 padding to the episode name
|
# 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
|
||||||
@ -696,15 +701,17 @@ 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
|
||||||
@ -799,13 +806,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
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
inf "Invalid option"
|
printf "%s\n" "Invalid option"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -836,20 +843,20 @@ main() {
|
|||||||
lg "Most recently watched episode: $ep_choice_start"
|
lg "Most recently watched episode: $ep_choice_start"
|
||||||
;;
|
;;
|
||||||
sync)
|
sync)
|
||||||
prompt "Enter username for remote user: "
|
printf "%s" "Enter username for remote user: "
|
||||||
read -r username
|
read -r username
|
||||||
prompt "Enter host for remote user: "
|
printf "%s" "Enter host for remote user: "
|
||||||
read -r host
|
read -r host
|
||||||
|
|
||||||
connection_str="$username@$host"
|
connection_str="$username@$host"
|
||||||
prompt "Enter port to connect to remote host with or leave blank for default (22): "
|
printf "%s" "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"
|
||||||
|
|
||||||
prompt "Enter path to private key (leave blank if unsure or not needed): "
|
printf "%s" "Enter path to private key (leave blank if unsure or not needed): "
|
||||||
read -r key_path
|
read -r key_path
|
||||||
|
|
||||||
lg "Syncing database with: $connection_str on port $PORT"
|
printf "%s\n" "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
|
||||||
@ -895,22 +902,24 @@ main() {
|
|||||||
episode=${ep_choice_end:-$ep_choice_start}
|
episode=${ep_choice_end:-$ep_choice_start}
|
||||||
choice=''
|
choice=''
|
||||||
while :; do
|
while :; do
|
||||||
inf "Currently playing $selection_id episode" "$episode/$last_ep_number"
|
printf "\n${c_green}Currently playing %s episode ${c_cyan}%d/%d\n" "$selection_id" $episode $last_ep_number
|
||||||
if ((episode != last_ep_number)); then
|
if [ "$episode" -ne "$last_ep_number" ]; then
|
||||||
menu_line_alternate "next episode" "n"
|
printf "$c_blue[${c_cyan}%s$c_blue] $c_yellow%s$c_reset\n" "n" "next episode"
|
||||||
fi
|
fi
|
||||||
if ((episode != first_ep_number)); then
|
if [ "$episode" -ne "1" ]; then
|
||||||
menu_line_alternate "previous episode" "p"
|
printf "$c_blue[${c_cyan}%s$c_blue] $c_magenta%s$c_reset\n" "p" "previous episode"
|
||||||
fi
|
fi
|
||||||
if ((first_ep_number != last_ep_number)); then
|
if [ "$last_ep_number" -ne "1" ]; then
|
||||||
menu_line_alternate "select episode" "s"
|
printf "$c_blue[${c_cyan}%s$c_blue] $c_yellow%s$c_reset\n" "s" "select episode"
|
||||||
fi
|
fi
|
||||||
menu_line_alternate "replay current episode" "r"
|
printf "$c_blue[${c_cyan}%s$c_blue] $c_magenta%s$c_reset\n" "r" "replay current episode"
|
||||||
menu_line_alternate "search for another anime" "a"
|
printf "$c_blue[${c_cyan}%s$c_blue] $c_yellow%s$c_reset\n" "a" "search for another anime"
|
||||||
menu_line_alternate "select quality (current: $quality)" "Q"
|
printf "$c_blue[${c_cyan}%s$c_blue] $c_magenta%s$c_reset\n" "Q" "change video quality (current: $quality)"
|
||||||
menu_line_strong "exit" "q"
|
printf "$c_blue[${c_cyan}%s$c_blue] $c_red%s$c_reset\n" "q" "exit"
|
||||||
prompt "Enter choice"
|
printf "${c_blue}Enter choice:${c_green} "
|
||||||
read -r choice
|
read -r choice
|
||||||
|
|
||||||
|
printf "$c_reset"
|
||||||
case $choice in
|
case $choice in
|
||||||
n)
|
n)
|
||||||
episode=$((episode + 1))
|
episode=$((episode + 1))
|
||||||
@ -961,11 +970,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"
|
||||||
prompt "Choose quality: [$qualities]"
|
printf "${c_blue}Choose quality: [$qualities]:$c_reset "
|
||||||
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"
|
||||||
prompt "Choose quality: [$qualities]"
|
printf "${c_blue}Choose quality: [$qualities]:$c_reset "
|
||||||
read -r quality
|
read -r quality
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
@ -985,7 +994,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 "$@"
|
||||||
|
23
aniwrapper
23
aniwrapper
@ -61,20 +61,10 @@ Options:
|
|||||||
|
|
||||||
lg() {
|
lg() {
|
||||||
if ((VERBOSE == 1)); then
|
if ((VERBOSE == 1)); then
|
||||||
inf "$*"
|
printf "%s\n" "$*"
|
||||||
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
|
||||||
@ -120,11 +110,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"
|
||||||
prompt "Choose quality " "[$qualities]"
|
printf "%s" "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]"
|
||||||
prompt "Choose quality " "[$qualities]"
|
printf "%s" "Choose quality: [$qualities]: "
|
||||||
read -r QUALITY
|
read -r QUALITY
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
@ -260,7 +250,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"
|
||||||
prompt "Enter player"
|
printf "%s" "Enter player: "
|
||||||
read -r PLAYER_FN
|
read -r PLAYER_FN
|
||||||
fi
|
fi
|
||||||
[ -z "$PLAYER_FN" ] && PLAYER_FN=mpv
|
[ -z "$PLAYER_FN" ] && PLAYER_FN=mpv
|
||||||
@ -282,7 +272,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
|
||||||
prompt "Enter download directory"
|
printf "%s" "Enter download dir: "
|
||||||
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
|
||||||
@ -308,9 +298,6 @@ 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