I've long been a fan of mpd
(Music Player Daemon) but recently I've been frustrated in that it can't play the BBC
radio feeds for some reason. So I've been looking for various working scripts, and I've found one, actually two as its a
two-parter, but this works, so thanks to its author Stephen C Phillips at http://blog.scphillips.com/.
So on with the scripts.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #!/bin/bash
# This script is based on one found in what is assumed to be the public domain.
# source - http://blog.scphillips.com/2014/05/bbc-radio-on-the-raspberry-pi-v2/
set -e
playlist=/home/USER/.mpd/playlists/beeb.m3u
rm -f $playlist
declare -A radios
radios["BBC1"]="http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-aac-lc-a/vpid/bbc_radio_one/format/pls.pls"
radios["BBC1x"]="http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-aac-lc-a/vpid/bbc_1xtra/format/pls.pls"
radios["BBC2"]="http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-aac-lc-a/vpid/bbc_radio_two/format/pls.pls"
radios["BBC3"]="http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-aac-lc-a/vpid/bbc_radio_three/format/pls.pls"
radios["BBC4"]="http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-aac-lc-a/vpid/bbc_radio_fourfm/format/pls.pls"
radios["BBC4x"]="http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-aac-lc-a/vpid/bbc_radio_four_extra/format/pls.pls"
radios["BBC5l"]="http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-aac-lc-a/vpid/bbc_radio_five_live/format/pls.pls"
radios["BBC5lx"]="http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-aac-lc-a/vpid/bbc_radio_five_live_sports_extra/format/pls.pls"
radios["BBC6"]="http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-aac-lc-a/vpid/bbc_6music/format/pls.pls"
radios["BBCan"]="http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-aac-lc-a/vpid/bbc_asian_network/supplier/ll_icy2/format/pls.pls"
for k in "${!radios[@]}"
do
pls=${radios[$k]}
curl -s $pls | grep File1 | sed "s/File1=/$k, /" >> "$playlist"
done
|
This is saved as bbcupdate
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #!/bin/sh
URLS=/home/USER/.mpd/playlists/beeb.m3u
[ ! -f $URLS ] && bbcupdate
case "$1" in
"stop")
mpc -q clear
;;
"status")
mpc | grep -vE "^volume:" | sed "s/^http:.*/Unknown station/"
;;
"stations")
cat $URLS | cut -d',' -f1 | sort
;;
"reset")
echo "Fetching station URLs…"
mpc -q clear
bbcupdate
;;
*)
grep -i "$1.*, " $URLS > /dev/null
if [ $? -eq 0 ]; then
mpc -q clear
mpc -q add `grep -i "$1.*, " $URLS | head -1 | cut -d',' -f2`
mpc -q play
sleep 2
mpc | grep "ERROR: problems decoding" > /dev/null
if [ $? -eq 0 ]; then
echo "Fetching station URLs…"
mpc -q clear
bbcupdate
mpc -q add `grep -i "$1.*, " $URLS | head -1 | cut -d',' -f2`
mpc -q play
fi
mpc | grep -vE "^volume:" | sed "s/^http:.*/Unknown station/"
else
echo "No such station"
fi
;;
esac
|
This is saved as radio
.
To start listening to one of the radio stations, first run "bbcupdate" then your radio commands are -
radio stations ;; gives a list of all available stations
radio status ;; shows what station is playing, and how long for
radio reset ;; stops all playing and runs "bbcupdate" again
radio stop ;; stops the radio playing
radio foo ;; your chosen radio station
If you want an explanation of how the scripts are working I can only refer you to Steven Phillips original article.
Using cron it is now being updated every two hours, using this line -
``00 */2 * * * /home/USERS/bin/bbcupdate``
Comments
comments powered by Disqus