Posts Tagged: iplayer


21
Feb 09

Record BBC Listen Again programs to MP3 in Ubuntu

A couple of weeks ago, the BBC had a brilliant program scheduled on Radio 4 but which I was unable to find time to listen to. Having missed the program, I though I would be able to download a podcast to my MP3 player and listen to it in my own time – however it quickly became apparent that this would not be the case. The BBC only provides podcasts for a very small proportion of its content and for everything else it encourages listeners to use its iPlayer software to ‘listen again’ within a week of the content being broadcast. I was however disappointed to discover that this iPlayer software is based upon Macromedia Flash and uses encrypted MP3 streams for audio playback – meaning that it is very difficult for you to record this audio stream to a file on your computer.

Luckily, however, I was happy to come across a website called iplayerconverter which provides links to the same audio streams available in the iPlayer but in Real Media format rather than the protected flash format. Whilst Real Media format audio streams are far from ideal, they can be successfully recorded to file in Linux.

I found the stream I was looking for on the above website and sure enough, was able to play it on my ubuntu box, now I just had to find a way to record it. After a bit of research, I whipped up a small shell script that would allow me to record any stream from the BBC iPlayer and record it to an uncompressed 16-bit PCM audio WAV file before compressing it to MP3 format, here is the code I used.

#/bin/bash
#  Created by Jonathan Lumb (http://sprayfly.com).
# This shell script will record a 'Listen Again' program from the BBC website to MP3 format.
# URL= Real Time Streaming Protocol (rtsp) address of the radio programme (see http://www.iplayerconverter.co.uk)
# NAME = file name
# VBR = Variable bitrate quality setting (0-9) 0=highest quality, default=4
echo "Please enter the Stream URL for the program you wish to record, eg. http://www.iplayerconverter.co.uk/pid/b00hhn4z/stream.aspx"
read URL
echo "Please enter a name for the program"
read NAME
echo "Enter the variable bitrate for the MP3 file (0-9), 0 is the highest quality."
read VBR
mplayer -cache 2048 -bandwidth 9999999 -playlist ""$URL"" -vc null -vo null -ao pcm:fast:waveheader:file="$NAME".wav
lame -V "$VBR" "$NAME".wav "$NAME".mp3
rm "$NAME".wav

To use this script simply open up a terminal on your ubuntu box and enter the following:

cd ~
nano iplayer.sh
(paste in the above code)
save [Ctrl]+[O]
exit [Ctrl]+[X]
chmod u+x iplayer.sh

To run the script, simply enter:
~/iplayer.sh

Now follow the instructions provided in the script – notably you will need to provide the RTSP URL for the stream you want to listen to (which can be found on http://www.iplayerconverter.co.uk and a name for the program you are recording (you can make up anything you want). You can also enter a value for the VBR rate – which determines the quality of the MP3 file the script will create. Once the script is finished (it can take some time) there should be an MP3 file saved in your home directory.

A few things to note:

You will need to have the following things installed for the above script to work:

  • Mplayer (to install, enter sudo apt-get install mplayer in a terminal)
  • Lame (to install, enter sudo apt-get install lame
  • Some audio codecs such as ffmpeg

The recording may take a while but shouldn’t be in real time – hence if you are recording an hour long program it may actually only take 10 or 20 minutes to finish recording.

Good Luck, let me know how you get on!