dotfiles/home/Scripts/mpvqueue

34 lines
843 B
Plaintext
Raw Normal View History

#!/usr/bin/env bash
MPVPIPE=/tmp/mpvqueue.playlist
notify="notify-send -i mpv -a mpv"
2020-03-02 21:38:33 +02:00
# if link is a youtube playlist, clean up url
if [[ ${1} =~ /^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$ ]]; then
url="https://youtube.com/playlist?list=${1#*list=}"
else
url="$1"
fi
# See if MPV is already running
if [ -z "$(pidof mpv)" ]; then
# mpv is not running
# remove fifo
rm -f $MPVPIPE && mkfifo $MPVPIPE
# start mpv
2020-03-02 21:38:33 +02:00
/usr/bin/mpv --no-terminal --input-file="${MPVPIPE}" "$url" & disown
# Wait for mpv to be up before moving on to 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 "loadfile \"$url\" append-play" >> "${MPVPIPE}"
fi