dotfiles/scripts/media/mpvqueue

31 lines
683 B
Text
Raw Normal View History

#!/usr/bin/env bash
notify="notify-send -i mpv -a mpv"
url="$1"
# NOTE: You need to configure mpv to
# enable ipc server on this path (see my mpv config for an example)
MPVSOCKET="/tmp/mpvsocket"
# See if MPV is already running
if [ -z "$(pidof mpv)" ]; then
# mpv is not running
# pause other players
playerctl pause
# start mpv
/usr/bin/mpv --no-terminal "$url" & disown
# Wait for mpv to be up before adding anything else to playlist
while [ -z "$(pidof mpv)" ]; do
sleep 1
done
2020-03-02 21:38:33 +02:00
$notify "Playing $url"
else
# mpv is running, so add stuff to playlist
2020-03-02 21:38:33 +02:00
$notify "Adding $url"
echo "{\"command\": [\"loadfile\", \"$url\", \"append\"]}" | socat - /tmp/mpvsocket
fi