Scripts: Update play queue to use the --input-ipc-server option
This commit is contained in:
+18
-20
@@ -1,6 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
PIPE="$XDG_CACHE_HOME/mpv/umpv_fifo"
|
||||
# Depends: socat
|
||||
|
||||
SOCK="/tmp/umpv-fifo"
|
||||
|
||||
help() {
|
||||
B=$(tput bold)
|
||||
@@ -35,10 +37,10 @@ ${B}OPTIONS${N}
|
||||
EOF
|
||||
}
|
||||
|
||||
CLIP="$(xclip -se c -o)"
|
||||
CLIP="$(xclip -selection clipboard -out)"
|
||||
|
||||
play() {
|
||||
MPV="mpv --ytdl-raw-options=external-downloader=aria2c"
|
||||
MPV="mpv --ytdl-raw-options=add-metadata=,external-downloader=aria2c"
|
||||
if [ -z "$1" ]; then
|
||||
MPV="$MPV $CLIP"
|
||||
# Cut off everything after space
|
||||
@@ -59,22 +61,21 @@ play() {
|
||||
shuffle() {
|
||||
# Skip first argument
|
||||
shift 1
|
||||
mpv --no-video --shuffle \
|
||||
--ytdl-format='bestaudio[ext=m4a]' \
|
||||
--ytdl-raw-options='external-downloader=aria2c' \
|
||||
"${@:-$CLIP}"
|
||||
setsid -f mpv --no-video --shuffle \
|
||||
--ytdl-format='bestaudio[ext=m4a]' \
|
||||
"${@:-$CLIP}"
|
||||
}
|
||||
|
||||
queue() {
|
||||
OPTIONS="--no-terminal --force-window --input-file=$PIPE --ytdl-raw-options=external-downloader=aria2c"
|
||||
OPTIONS="--no-terminal --force-window --input-ipc-server=$SOCK --"
|
||||
|
||||
# Create mpv cache directory
|
||||
DIR="$(dirname "$PIPE")"
|
||||
DIR="$(dirname "$SOCK")"
|
||||
[ ! -d "$DIR" ] && mkdir -p "$DIR"
|
||||
|
||||
# Delete named pipe if no umpv is running
|
||||
# Delete socket if no umpv is running
|
||||
if ! pgrep -f "mpv $OPTIONS" > /dev/null; then
|
||||
rm -f "$PIPE"
|
||||
rm -f "$SOCK"
|
||||
fi
|
||||
|
||||
# Skip first argument
|
||||
@@ -82,19 +83,16 @@ queue() {
|
||||
# Set url to argument if provided, clipboard otherwise
|
||||
URLS="${*:-$CLIP}"
|
||||
|
||||
if [ -p "$PIPE" ]; then
|
||||
if [ -S "$SOCK" ]; then
|
||||
notify-send -t 2500 "Added video to queue.."
|
||||
# Add video to named pipe
|
||||
echo "$URLS" \
|
||||
| awk -v RS=' ' '{ print "raw loadfile "$1" append" }' > "$PIPE"
|
||||
echo "$URLS" | awk -v RS=' ' '{ print "raw loadfile "$1" append" }' \
|
||||
| socat UNIX-CONNECT:"$SOCK" -
|
||||
else
|
||||
# Create named pipe
|
||||
mkfifo "$PIPE"
|
||||
|
||||
# Play video
|
||||
play "$OPTIONS" "$URLS"
|
||||
|
||||
rm -f "$PIPE"
|
||||
notify-send -t 2500 "Loading video: $URLS"
|
||||
# shellcheck disable=2086
|
||||
setsid -f mpv $OPTIONS $URLS
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user