foodotfiles/home/Scripts/mpvqueue
Marko Korhonen b1335a3628 Removed commit history
Signed-off-by: Marko Korhonen <marko.korhonen@reekynet.com>
2019-10-26 20:05:31 +03:00

34 lines
864 B
Bash
Executable File

#!/usr/bin/env bash
MPVPIPE=/tmp/mpvqueue.playlist
notify="notify-send -i mpv -a mpv"
# if link is a youtube playlist, open recursively
if [[ ${1} =~ (^.*(youtu.be\/|list=)([^#\&\?]*).*) ]]; then
$notify "Adding playlist ${@}"
/usr/local/bin/mpvqueue $(youtube-dl -j --flat-playlist "${1}" | jq -r '.id' | sed 's_^_https://youtube.com/watch?v=_')
exit
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
/usr/bin/mpv --no-terminal --input-file="${MPVPIPE}" "${@}" & disown
# Wait for mpv to be up before moving on to adding anything else to playlist
while [ -z "$(pidof mpv)" ]; do
sleep 1
done
$notify "Playing ${@}"
else
# mpv is running, so add stuff to playlist
$notify "Adding ${@}"
echo "loadfile \"${@}\" append-play" >> "${MPVPIPE}"
fi