radio/radio.sh
2017-02-27 09:47:30 +00:00

32 lines
524 B
Bash
Executable file

#!/bin/sh
radio_play() {
link=$1
yt_vid=$(youtube-dl --no-playlist -g -f 140 "$link")
title=$(wget -q -O - "$link" | sed -n 's/<title>\(.*\) - YouTube<\/title>/\1/Ip' | cut -d '<' -f 1 | base64 | tr -d '\n')
mpc add "$yt_vid#$title"
echo "new song $link"
}
pipe="/tmp/radio"
trap "rm -rf $pipe" EXIT
if [[ ! -p $pipe ]];
then
mkfifo $pipe
chmod 666 $pipe
fi
mpc random on
mpc repeat on
mpc crossfade 10
while :
do
if read line < $pipe;
then
radio_play $line
mpc play
fi
done