mirror of
https://git.korhonen.cc/FunctionalHacker/dotfiles.git
synced 2024-11-04 18:00:20 +00:00
b1335a3628
Signed-off-by: Marko Korhonen <marko.korhonen@reekynet.com>
34 lines
864 B
Bash
Executable File
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
|