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