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