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!
Tags: again, audio, bbc, iplayer, lame, listen, mplayer, recording
Thanks for the mention – I’m glad you find the site useful! I do something very similar myself for shows I want to listen to, although I use Windows utilities instead of mplayer/lame.
I do welcome all suggestions for improvements, or any other feedback.
Hi Andrew – thanks for the comment. I’ve sent you an email in reply
Above works like a dream for a programme I did not want to listen to but not for the programme I want to listen too I get
Playing http://www.bbc.co.uk/iplayer/console/.
Resolving http://www.bbc.co.uk for AF_INET6…
Couldn’t resolve name for AF_INET6: http://www.bbc.co.uk
Resolving http://www.bbc.co.uk for AF_INET…
Connecting to server http://www.bbc.co.uk212.58.251.195: 80…
Server returned 404: Not Found
STREAM_ASF, URL: http://www.bbc.co.uk/iplayer/console/
Resolving http://www.bbc.co.uk for AF_INET6…
Couldn’t resolve name for AF_INET6: http://www.bbc.co.uk
Resolving http://www.bbc.co.uk for AF_INET…
Connecting to server http://www.bbc.co.uk212.58.251.195: 80…
Server returned 404:Not Found
Failed to parse header.
Failed, exiting.
Resolving http://www.bbc.co.uk for AF_INET6…
Couldn’t resolve name for AF_INET6: http://www.bbc.co.uk
Resolving http://www.bbc.co.uk for AF_INET…
Connecting to server http://www.bbc.co.uk212.58.251.195: 80…
Server returned 404: Not Found
No stream found to handle url http://www.bbc.co.uk/iplayer/console/
Exiting… (End of file)
Could not find “cuba.wav”.
rm: cannot remove `cuba.wav’: No such file or directory
tried site above and going to iplayer and pasting the url from there. Cuba is the name of the file I attempted to create. Must be a problem at the BBC’s end. I was hoping this would get round my sound problem in that flash sound doesn’t work but mp3′s do!
Hi
I like to record the show here:
http://www.radiojavan.com/onradio/podcast/Norooz1388Mix-DJTaba
I can verify that the site is sending me the content through sniffing the traffic with wireshark. But the rest like creating a file etc. Does not happen. Here is a copy of edited script you provided above:
#/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.iplayerconverte
r.co.uk)
# NAME = file name
# VBR = Variable bitrate quality setting (0-9) 0=highest quality,
default=4
echo “http://www.radiojavan.com/onradio/podcast/Norooz1388Mix-DJTaba”
read URL
echo “irooni”
read NAME
echo “0″
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
I am sure I did something wrong in the script
Hi Sean
I’m afraid that I only tested this script with the BBC website – it may not work with streams from other websites and in different formats. Have you tested the script with a BBC stream to make sure it is not something else wrong in your setup?
Hi Jono,
That is a good idea. I’ll do that, and maybe look at some of the log files for possible errors.
Regards-
Sean
Hi Jono – really good stuff. Worked like a charm.
Glad that the script was useful!
Hi,
I have been trying to record a Radio 4 program “Inside the Virtual Anthill: Open Source Means Business” (http://www.iplayerconverter.co.uk/pid/b00kp806/stream.aspx) but I get the following message:
Could not parse arguments at the position indicated below:
fast:waveheader:file=Inside the Virtual Anthill: Open Source Means Business.wav
^
Could not open/initialize audio device -> no sound.
Audio: no sound
Video: no video
Exiting… (End of file)
Could not find “Inside the Virtual Anthill: Open Source Means Business.wav”.
rm: cannot remove `Inside the Virtual Anthill: Open Source Means Business.wav’: No such file or directory
Any ideas on what when wrong??
Inside the Virtual Anthill: Open Source Means Business.wav is not a valid unix filename – UNIX filenames only contain letters, numbers, and the _ (underscore) and . (dot) characters. All other characters should be avoided. I suspect that this is part of the problem.
OK, I had another go, this time I went to the program page in iPlayer and looked at the page source (Ctrl U), then used the link for the ram (http://www.bbc.co.uk/iplayer/aod/playlists/zy/7p/k0/0b/RadioBridge_uk_2000_bbc_radio_fourfm.ram) and this time it worked. Now all I need is to find what it does with the out put, there must be an mp3 file somewhere…
Found the file, for any other novices out there to find the file you have to “show hidden files” as the output is simply .mp3, you can then rename it to something.mp3 so that is no longer hidden.
I spent ages writing my own script to do this 6 months back and now I find this, it works like a charm.
But…
Does anyone know how to download the TV programs instead of radio? That’s my next goal.
Afraid I can’t help you on that one… good luck!
Great script – worked a treat – 30 minute program recorded in mp3 in less than 5 minutes.
Outstanding. I have been using a (Windows) app for a few years that simply captured the output from my sound card, which was pretty inefficient since it took 2 hours to record a 2 hour show, and required you to actually play the file. When they switched to the new encoded URL that they use with the iPlayer, it broke my scripts and I never got it fixed back up.
The next extension is to work out a nice way to automate how to get the URL and date of transmission out of that website (I’m thinking perhaps using links2 -dump and somehow parsing the output with awk or something) – if I get it going I’ll add it to this.
Hi Phil
Do let me know if you get this up and running as I think lots of people would be interested.
Glad you found the post useful anyway…
Jono – I mailed you with my current app for harvesting that other site and automating the process of getting your favourite shows. It’s far from perfect, but there might be stuff worth taking from it. Let me know if it doesn’t arrive.
Phil J
Brilliant, works like a charm.
This truly is brilliant.
Such a useful script and it works perfectly.
Thank you!