mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-11-22 03:19:53 -08: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"
|
||||
HISTORY_DB="$CFG_DIR/history.sqlite3"
|
||||
PLAYER_CMD="mpv"
|
||||
ROFI_CFG="$CFG_DIR/themes/aniwrapper.rasi"
|
||||
ROFI_THEME="aniwrapper.rasi"
|
||||
THEMES="aniwrapper (default)|dracula|doomone|fancy|flamingo|material|nord|onedark"
|
||||
@ -42,7 +41,6 @@ check_input() {
|
||||
episodes=$ep_choice_start
|
||||
if [ -n "$ep_choice_end" ]; then
|
||||
[ "$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)
|
||||
fi
|
||||
}
|
||||
@ -254,8 +252,7 @@ sync_search_history() {
|
||||
errs=0
|
||||
while read -r line; do
|
||||
anime_name=$(awk -F '|' '{print $2}' <<< "$line")
|
||||
res=$(sqlite3 -noheader "$HISTORY_DB" "SELECT COUNT(*) FROM search_history WHERE anime_name = '$anime_name'")
|
||||
if [[ "$res" -eq 0 ]]; then
|
||||
if sqlite3 -noheader "$HISTORY_DB" "SELECT COUNT(*) FROM search_history WHERE anime_name = '$anime_name'"; then
|
||||
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
|
||||
((++errs))
|
||||
@ -291,7 +288,7 @@ sync_watch_history() {
|
||||
### Play from file###
|
||||
#####################
|
||||
|
||||
# opens the passed in file with $PLAYER_CMD
|
||||
# opens the passed in file with $player_fn
|
||||
play_file() {
|
||||
lg "Checking if file is playable"
|
||||
if [[ "$1" =~ ($playable)$ ]]; then
|
||||
@ -299,12 +296,21 @@ play_file() {
|
||||
directory="${1%/*}"
|
||||
insert_history "file" "$directory" "$filename" &
|
||||
if [[ "$1" =~ .mp3 ]]; then
|
||||
lg ".mp3 file found... playing without video"
|
||||
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
|
||||
notification "Playing $1"
|
||||
$PLAYER_CMD "$1" > /dev/null 2>&1 &
|
||||
nohup "$player_fn" "$1" > /dev/null 2>&1 &
|
||||
fi
|
||||
return $?
|
||||
else
|
||||
@ -413,7 +419,6 @@ get_search_query() {
|
||||
query=$(rofi -dpi "$DPI" -dmenu -l 15 -p "Search Anime:" \
|
||||
-mesg "$(generate_span "$msg")" \
|
||||
-config "$ROFI_CFG" < <(run_stmt "$stmt"))
|
||||
# Remove the id from the query
|
||||
query="${query//[1-9]*\. /}"
|
||||
lg "Query: $query"
|
||||
elif [ "$IS_ROFI" -eq 0 ]; then
|
||||
@ -493,8 +498,7 @@ anime_selection() {
|
||||
fi
|
||||
|
||||
choice=$(printf '%s\n' "$user_input" | awk '{print $1}')
|
||||
# Remove period after number
|
||||
choice="${choice::-1}"
|
||||
choice="${choice::-1}" # Remove period after number
|
||||
name=$(printf '%s\n' "$user_input" | awk '{print $NF}')
|
||||
else
|
||||
menu_format_string='[%d] %s\n'
|
||||
@ -516,12 +520,9 @@ anime_selection() {
|
||||
name="$anime_id"
|
||||
fi
|
||||
|
||||
lg "CHOICE: $choice"
|
||||
|
||||
# Check if input is a number
|
||||
[ "$choice" -eq "$choice" ] 2> /dev/null || die "Invalid number entered"
|
||||
|
||||
# Select respective anime_id
|
||||
count=1
|
||||
while read -r anime_id; do
|
||||
if [ "$count" -eq "$choice" ]; then
|
||||
@ -547,7 +548,6 @@ anime_selection() {
|
||||
episode_selection() {
|
||||
ep_choice_start="1"
|
||||
if [ "$IS_ROFI" -eq 1 ]; then
|
||||
# select episode number for anime
|
||||
lg "Anime ID: $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
|
||||
printf "$c_reset"
|
||||
fi
|
||||
# check for half episode
|
||||
if [ "$(echo "$ep_choice_start" | awk '{ printf substr($0, 1, 1) }')" = "h" ]; then
|
||||
lg "IS A HALF EPISODE"
|
||||
half_ep=1
|
||||
@ -637,7 +636,21 @@ open_episode() {
|
||||
|
||||
if [ "$is_download" -eq 0 ]; then
|
||||
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=$!
|
||||
if command -v "notify-send" > /dev/null; then
|
||||
((SILENT != 1)) && notify-send -i "$ANIWRAPPER_ICON_PATH" "Playing $anime_id - Episode $episode"
|
||||
@ -704,7 +717,7 @@ parse_args() {
|
||||
is_download=0
|
||||
download_dir="."
|
||||
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
|
||||
d)
|
||||
is_download=1
|
||||
@ -792,6 +805,12 @@ parse_args() {
|
||||
S)
|
||||
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"
|
||||
exit 1
|
||||
@ -832,11 +851,7 @@ main() {
|
||||
connection_str="$username@$host"
|
||||
printf "%s" "Enter port to connect to remote host with or leave blank for default (22): "
|
||||
read -r port
|
||||
if [[ "${port/ //}" == "" ]]; then
|
||||
PORT=22
|
||||
else
|
||||
PORT="$port"
|
||||
fi
|
||||
[ -z "$port" ] && PORT=22 || PORT="$port"
|
||||
|
||||
printf "%s" "Enter path to private key (leave blank if unsure or not needed): "
|
||||
read -r key_path
|
||||
|
36
aniwrapper
36
aniwrapper
@ -12,7 +12,9 @@ DEFAULT_DOWNLOAD="$HOME/Videos/sauce"
|
||||
ROFI_THEME="aniwrapper.rasi"
|
||||
THEMES="aniwrapper (default)|dracula|doomone|fancy|flamingo|material|nord|onedark"
|
||||
QUALITIES="1. best|2. 1080p|3. 720p|4. 360p|5. worst"
|
||||
SUPPORTED_PLAYERS="mpv|mplayer|vlc"
|
||||
QUALITY=best
|
||||
PLAYER_FN=mpv
|
||||
DPI=96
|
||||
GET_QUALITY=0
|
||||
IS_CUSTOM_THEME=0
|
||||
@ -20,6 +22,7 @@ IS_DOWNLOAD=0
|
||||
IS_PLAY_FROM_FILE=0
|
||||
IS_ROFI=1
|
||||
IS_SYNC=0
|
||||
IS_ALTERNATE_PLAYER=0
|
||||
VERBOSE=0
|
||||
SILENT=0
|
||||
|
||||
@ -76,21 +79,21 @@ run() {
|
||||
fi
|
||||
if ((SILENT == 1)); 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
|
||||
"$CMD" -D"$DPI" -Sq "$QUALITY" -T "$CFG_FILE" "$@"
|
||||
"$CMD" -D"$DPI" -Sq "$QUALITY" -T "$CFG_FILE" -p "$PLAYER_FN" "$@"
|
||||
fi
|
||||
elif ((VERBOSE == 1)); 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
|
||||
"$CMD" -D"$DPI" -vq "$QUALITY" -T "$CFG_FILE" "$@"
|
||||
"$CMD" -D"$DPI" -vq "$QUALITY" -T "$CFG_FILE" -p "$PLAYER_FN" "$@"
|
||||
fi
|
||||
else
|
||||
if ((IS_CUSTOM_THEME == 0)); then
|
||||
"$CMD" -D"$DPI" -q "$QUALITY" -t "$theme" "$@"
|
||||
"$CMD" -D"$DPI" -q "$QUALITY" -t "$theme" -p "$PLAYER_FN" "$@"
|
||||
else
|
||||
"$CMD" -D"$DPI" -q "$QUALITY" -T "$CFG_FILE" "$@"
|
||||
"$CMD" -D"$DPI" -q "$QUALITY" -T "$CFG_FILE" -p "$PLAYER_FN" "$@"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@ -160,7 +163,7 @@ set_theme() {
|
||||
}
|
||||
|
||||
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
|
||||
h)
|
||||
help_text
|
||||
@ -213,6 +216,9 @@ parse_args() {
|
||||
S)
|
||||
SILENT=1
|
||||
;;
|
||||
p)
|
||||
IS_ALTERNATE_PLAYER=1
|
||||
;;
|
||||
*)
|
||||
help_text
|
||||
exit 1
|
||||
@ -226,6 +232,22 @@ check_flags() {
|
||||
if ((VERBOSE == 1 && SILENT == 1)); then
|
||||
seppuku "verbose and silent options cannot be used together"
|
||||
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
|
||||
run -c "$@"
|
||||
exit $?
|
||||
|
Loading…
Reference in New Issue
Block a user