mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-10-28 04:44:11 -07:00
add ability to supply player function (mpv/mplayer/vlc fully supported)
This commit is contained in:
parent
cf7cf4b591
commit
5c7af5c36d
61
ani-cli
61
ani-cli
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/aniwrapper"
|
CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/aniwrapper"
|
||||||
HISTORY_DB="$CFG_DIR/history.sqlite3"
|
HISTORY_DB="$CFG_DIR/history.sqlite3"
|
||||||
PLAYER_CMD="mpv"
|
|
||||||
ROFI_CFG="$CFG_DIR/themes/aniwrapper.rasi"
|
ROFI_CFG="$CFG_DIR/themes/aniwrapper.rasi"
|
||||||
ROFI_THEME="aniwrapper.rasi"
|
ROFI_THEME="aniwrapper.rasi"
|
||||||
THEMES="aniwrapper (default)|dracula|doomone|fancy|flamingo|material|nord|onedark"
|
THEMES="aniwrapper (default)|dracula|doomone|fancy|flamingo|material|nord|onedark"
|
||||||
@ -42,7 +41,6 @@ check_input() {
|
|||||||
episodes=$ep_choice_start
|
episodes=$ep_choice_start
|
||||||
if [ -n "$ep_choice_end" ]; then
|
if [ -n "$ep_choice_end" ]; then
|
||||||
[ "$ep_choice_end" -eq "$ep_choice_end" ] 2> /dev/null || die "Invalid number entered: $ep_choice_end"
|
[ "$ep_choice_end" -eq "$ep_choice_end" ] 2> /dev/null || die "Invalid number entered: $ep_choice_end"
|
||||||
# create list of episodes to download/watch
|
|
||||||
episodes=$(seq $ep_choice_start $ep_choice_end)
|
episodes=$(seq $ep_choice_start $ep_choice_end)
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -254,8 +252,7 @@ sync_search_history() {
|
|||||||
errs=0
|
errs=0
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
anime_name=$(awk -F '|' '{print $2}' <<< "$line")
|
anime_name=$(awk -F '|' '{print $2}' <<< "$line")
|
||||||
res=$(sqlite3 -noheader "$HISTORY_DB" "SELECT COUNT(*) FROM search_history WHERE anime_name = '$anime_name'")
|
if sqlite3 -noheader "$HISTORY_DB" "SELECT COUNT(*) FROM search_history WHERE anime_name = '$anime_name'"; then
|
||||||
if [[ "$res" -eq 0 ]]; then
|
|
||||||
search_date=$(awk -F '|' '{print $3}' <<< "$line")
|
search_date=$(awk -F '|' '{print $3}' <<< "$line")
|
||||||
if ! sqlite3 "$HISTORY_DB" "INSERT INTO search_history(anime_name, search_date) VALUES('$anime_name', '$search_date')"; then
|
if ! sqlite3 "$HISTORY_DB" "INSERT INTO search_history(anime_name, search_date) VALUES('$anime_name', '$search_date')"; then
|
||||||
((++errs))
|
((++errs))
|
||||||
@ -291,7 +288,7 @@ sync_watch_history() {
|
|||||||
### Play from file###
|
### Play from file###
|
||||||
#####################
|
#####################
|
||||||
|
|
||||||
# opens the passed in file with $PLAYER_CMD
|
# 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" =~ ($playable)$ ]]; then
|
||||||
@ -299,12 +296,21 @@ play_file() {
|
|||||||
directory="${1%/*}"
|
directory="${1%/*}"
|
||||||
insert_history "file" "$directory" "$filename" &
|
insert_history "file" "$directory" "$filename" &
|
||||||
if [[ "$1" =~ .mp3 ]]; then
|
if [[ "$1" =~ .mp3 ]]; then
|
||||||
lg ".mp3 file found... playing without video"
|
|
||||||
notification "Playing $1"
|
notification "Playing $1"
|
||||||
$PLAYER_CMD --no-video "$1"
|
case "$player_fn" in
|
||||||
|
mpv)
|
||||||
|
nohup "$player_fn" --no-video "$1" > /dev/null 2>&1
|
||||||
|
;;
|
||||||
|
mplayer)
|
||||||
|
nohup "$player_fn" -novideo "$1" > /dev/null 2>&1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
nohup "$player_fn" "$1" > /dev/null 2>&1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
else
|
else
|
||||||
notification "Playing $1"
|
notification "Playing $1"
|
||||||
$PLAYER_CMD "$1" > /dev/null 2>&1 &
|
nohup "$player_fn" "$1" > /dev/null 2>&1 &
|
||||||
fi
|
fi
|
||||||
return $?
|
return $?
|
||||||
else
|
else
|
||||||
@ -413,7 +419,6 @@ get_search_query() {
|
|||||||
query=$(rofi -dpi "$DPI" -dmenu -l 15 -p "Search Anime:" \
|
query=$(rofi -dpi "$DPI" -dmenu -l 15 -p "Search Anime:" \
|
||||||
-mesg "$(generate_span "$msg")" \
|
-mesg "$(generate_span "$msg")" \
|
||||||
-config "$ROFI_CFG" < <(run_stmt "$stmt"))
|
-config "$ROFI_CFG" < <(run_stmt "$stmt"))
|
||||||
# Remove the id from the query
|
|
||||||
query="${query//[1-9]*\. /}"
|
query="${query//[1-9]*\. /}"
|
||||||
lg "Query: $query"
|
lg "Query: $query"
|
||||||
elif [ "$IS_ROFI" -eq 0 ]; then
|
elif [ "$IS_ROFI" -eq 0 ]; then
|
||||||
@ -493,8 +498,7 @@ anime_selection() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
choice=$(printf '%s\n' "$user_input" | awk '{print $1}')
|
choice=$(printf '%s\n' "$user_input" | awk '{print $1}')
|
||||||
# Remove period after number
|
choice="${choice::-1}" # Remove period after number
|
||||||
choice="${choice::-1}"
|
|
||||||
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='[%d] %s\n'
|
||||||
@ -516,12 +520,9 @@ anime_selection() {
|
|||||||
name="$anime_id"
|
name="$anime_id"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
lg "CHOICE: $choice"
|
|
||||||
|
|
||||||
# Check if input is a number
|
# Check if input is a number
|
||||||
[ "$choice" -eq "$choice" ] 2> /dev/null || die "Invalid number entered"
|
[ "$choice" -eq "$choice" ] 2> /dev/null || die "Invalid number entered"
|
||||||
|
|
||||||
# Select respective anime_id
|
|
||||||
count=1
|
count=1
|
||||||
while read -r anime_id; do
|
while read -r anime_id; do
|
||||||
if [ "$count" -eq "$choice" ]; then
|
if [ "$count" -eq "$choice" ]; then
|
||||||
@ -547,7 +548,6 @@ anime_selection() {
|
|||||||
episode_selection() {
|
episode_selection() {
|
||||||
ep_choice_start="1"
|
ep_choice_start="1"
|
||||||
if [ "$IS_ROFI" -eq 1 ]; then
|
if [ "$IS_ROFI" -eq 1 ]; then
|
||||||
# select episode number for anime
|
|
||||||
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';"
|
||||||
|
|
||||||
@ -586,7 +586,6 @@ episode_selection() {
|
|||||||
read ep_choice_start ep_choice_end
|
read ep_choice_start ep_choice_end
|
||||||
printf "$c_reset"
|
printf "$c_reset"
|
||||||
fi
|
fi
|
||||||
# check for half episode
|
|
||||||
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"
|
||||||
half_ep=1
|
half_ep=1
|
||||||
@ -637,7 +636,21 @@ open_episode() {
|
|||||||
|
|
||||||
if [ "$is_download" -eq 0 ]; then
|
if [ "$is_download" -eq 0 ]; then
|
||||||
kill "$PID" > /dev/null 2>&1
|
kill "$PID" > /dev/null 2>&1
|
||||||
nohup "$player_fn" --http-header-fields="Referer:$dpage_link" "$video_url" > /dev/null 2>&1 &
|
case "$player_fn" in
|
||||||
|
mpv)
|
||||||
|
nohup "$player_fn" --referrer="$dpage_link" "$video_url" > /dev/null 2>&1 &
|
||||||
|
;;
|
||||||
|
mplayer)
|
||||||
|
nohup "$player_fn" -referrer "$dpage_link" "$video_url" > /dev/null 2>&1 &
|
||||||
|
;;
|
||||||
|
vlc)
|
||||||
|
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 &
|
||||||
|
;;
|
||||||
|
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"
|
||||||
@ -704,7 +717,7 @@ parse_args() {
|
|||||||
is_download=0
|
is_download=0
|
||||||
download_dir="."
|
download_dir="."
|
||||||
half_ep=0
|
half_ep=0
|
||||||
while getopts 'd:Hsvq:cf:t:T:CQ:D:S' OPT; do
|
while getopts 'd:Hsvq:cf:t:T:CQ:D:Sp:' OPT; do
|
||||||
case "$OPT" in
|
case "$OPT" in
|
||||||
d)
|
d)
|
||||||
is_download=1
|
is_download=1
|
||||||
@ -792,6 +805,12 @@ parse_args() {
|
|||||||
S)
|
S)
|
||||||
SILENT=1
|
SILENT=1
|
||||||
;;
|
;;
|
||||||
|
p)
|
||||||
|
player_fn="$OPTARG"
|
||||||
|
if ! command -v "$player_fn" > /dev/null; then
|
||||||
|
die "ERROR: $player_fn does not exist"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
printf "%s\n" "Invalid option"
|
printf "%s\n" "Invalid option"
|
||||||
exit 1
|
exit 1
|
||||||
@ -832,11 +851,7 @@ main() {
|
|||||||
connection_str="$username@$host"
|
connection_str="$username@$host"
|
||||||
printf "%s" "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
|
||||||
if [[ "${port/ //}" == "" ]]; then
|
[ -z "$port" ] && PORT=22 || PORT="$port"
|
||||||
PORT=22
|
|
||||||
else
|
|
||||||
PORT="$port"
|
|
||||||
fi
|
|
||||||
|
|
||||||
printf "%s" "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
|
||||||
|
36
aniwrapper
36
aniwrapper
@ -12,7 +12,9 @@ DEFAULT_DOWNLOAD="$HOME/Videos/sauce"
|
|||||||
ROFI_THEME="aniwrapper.rasi"
|
ROFI_THEME="aniwrapper.rasi"
|
||||||
THEMES="aniwrapper (default)|dracula|doomone|fancy|flamingo|material|nord|onedark"
|
THEMES="aniwrapper (default)|dracula|doomone|fancy|flamingo|material|nord|onedark"
|
||||||
QUALITIES="1. best|2. 1080p|3. 720p|4. 360p|5. worst"
|
QUALITIES="1. best|2. 1080p|3. 720p|4. 360p|5. worst"
|
||||||
|
SUPPORTED_PLAYERS="mpv|mplayer|vlc"
|
||||||
QUALITY=best
|
QUALITY=best
|
||||||
|
PLAYER_FN=mpv
|
||||||
DPI=96
|
DPI=96
|
||||||
GET_QUALITY=0
|
GET_QUALITY=0
|
||||||
IS_CUSTOM_THEME=0
|
IS_CUSTOM_THEME=0
|
||||||
@ -20,6 +22,7 @@ IS_DOWNLOAD=0
|
|||||||
IS_PLAY_FROM_FILE=0
|
IS_PLAY_FROM_FILE=0
|
||||||
IS_ROFI=1
|
IS_ROFI=1
|
||||||
IS_SYNC=0
|
IS_SYNC=0
|
||||||
|
IS_ALTERNATE_PLAYER=0
|
||||||
VERBOSE=0
|
VERBOSE=0
|
||||||
SILENT=0
|
SILENT=0
|
||||||
|
|
||||||
@ -76,21 +79,21 @@ run() {
|
|||||||
fi
|
fi
|
||||||
if ((SILENT == 1)); then
|
if ((SILENT == 1)); then
|
||||||
if ((IS_CUSTOM_THEME == 0)); then
|
if ((IS_CUSTOM_THEME == 0)); then
|
||||||
"$CMD" -D"$DPI" -Sq "$QUALITY" -t "$theme" "$@"
|
"$CMD" -D"$DPI" -Sq "$QUALITY" -t "$theme" -p "$PLAYER_FN" "$@"
|
||||||
else
|
else
|
||||||
"$CMD" -D"$DPI" -Sq "$QUALITY" -T "$CFG_FILE" "$@"
|
"$CMD" -D"$DPI" -Sq "$QUALITY" -T "$CFG_FILE" -p "$PLAYER_FN" "$@"
|
||||||
fi
|
fi
|
||||||
elif ((VERBOSE == 1)); then
|
elif ((VERBOSE == 1)); then
|
||||||
if ((IS_CUSTOM_THEME == 0)); then
|
if ((IS_CUSTOM_THEME == 0)); then
|
||||||
"$CMD" -D"$DPI" -vq "$QUALITY" -t "$theme" "$@"
|
"$CMD" -D"$DPI" -vq "$QUALITY" -t "$theme" -p "$PLAYER_FN" "$@"
|
||||||
else
|
else
|
||||||
"$CMD" -D"$DPI" -vq "$QUALITY" -T "$CFG_FILE" "$@"
|
"$CMD" -D"$DPI" -vq "$QUALITY" -T "$CFG_FILE" -p "$PLAYER_FN" "$@"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if ((IS_CUSTOM_THEME == 0)); then
|
if ((IS_CUSTOM_THEME == 0)); then
|
||||||
"$CMD" -D"$DPI" -q "$QUALITY" -t "$theme" "$@"
|
"$CMD" -D"$DPI" -q "$QUALITY" -t "$theme" -p "$PLAYER_FN" "$@"
|
||||||
else
|
else
|
||||||
"$CMD" -D"$DPI" -q "$QUALITY" -T "$CFG_FILE" "$@"
|
"$CMD" -D"$DPI" -q "$QUALITY" -T "$CFG_FILE" -p "$PLAYER_FN" "$@"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -160,7 +163,7 @@ set_theme() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parse_args() {
|
parse_args() {
|
||||||
while getopts 'vhqcdf:-:t:T:CQ:D:S' OPT; do
|
while getopts 'vhqcdf:-:t:T:CQ:D:Sp' OPT; do
|
||||||
case "$OPT" in
|
case "$OPT" in
|
||||||
h)
|
h)
|
||||||
help_text
|
help_text
|
||||||
@ -213,6 +216,9 @@ parse_args() {
|
|||||||
S)
|
S)
|
||||||
SILENT=1
|
SILENT=1
|
||||||
;;
|
;;
|
||||||
|
p)
|
||||||
|
IS_ALTERNATE_PLAYER=1
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
help_text
|
help_text
|
||||||
exit 1
|
exit 1
|
||||||
@ -226,6 +232,22 @@ check_flags() {
|
|||||||
if ((VERBOSE == 1 && SILENT == 1)); then
|
if ((VERBOSE == 1 && SILENT == 1)); then
|
||||||
seppuku "verbose and silent options cannot be used together"
|
seppuku "verbose and silent options cannot be used together"
|
||||||
fi
|
fi
|
||||||
|
if ((IS_DOWNLOAD == 0 && IS_ALTERNATE_PLAYER == 1)); then
|
||||||
|
msg1="Choose from the supported players, or supply your own player command (full functionality not guaranteed)"
|
||||||
|
msg2="if using an unsupported player, it must be able to play URLs for streaming from the internet"
|
||||||
|
PLAYER_FN=$(
|
||||||
|
awk '{print $NF}' < <(rofi -dmenu -config "$CFG_FILE" -DPI "$DPI" \
|
||||||
|
-l 4 -theme-str 'listview {columns: 1;} window {width: 40%;}' \
|
||||||
|
-p "Enter video player:" \
|
||||||
|
-mesg "$(printf "%s\n%s\n" "$(generate_span "$msg1")" "$(generate_span "$msg2")")" \
|
||||||
|
-a 0 -sep '|' <<< "$SUPPORTED_PLAYERS")
|
||||||
|
)
|
||||||
|
[ -z "$PLAYER_FN" ] && PLAYER_FN=mpv
|
||||||
|
if ! command -v "$PLAYER_FN" > /dev/null; then
|
||||||
|
seppuku "ERROR: $PLAYER_FN does not exist"
|
||||||
|
fi
|
||||||
|
lg "SELECTED PLAYER FN -> $PLAYER_FN"
|
||||||
|
fi
|
||||||
if ((IS_ROFI == 0 && IS_DOWNLOAD == 0)); then
|
if ((IS_ROFI == 0 && IS_DOWNLOAD == 0)); then
|
||||||
run -c "$@"
|
run -c "$@"
|
||||||
exit $?
|
exit $?
|
||||||
|
Loading…
Reference in New Issue
Block a user