mirror of
https://git.korhonen.cc/FunctionalHacker/dotfiles.git
synced 2024-11-08 13:10:37 +00:00
34 lines
864 B
Plaintext
34 lines
864 B
Plaintext
|
#!/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
|