tomtaylor.co.uk

Blog

How to rip BBC Radio streams to MP3

Friday, September 1st, 2006 at 7:11 pm in Uncategorized.

Tagged with: , .

Update: The information below has been superseded by two tools that do the same thing but much better.

BBC Radio Player is awesome. Being able to listen to the last 7 days of programming is absolutely great. But, often you want to listen to a BBC Radio programme on your iPod, away from an internet connected PC.

Assuming you’re using Linux, you need mplayer and mencoder installed. Get the direct URL of the stream you want to capture from dave.org.uk. I’ll use Book at Bedtime as an example…

This captures the stream and dumps it to a local file. It will take real time. A 15 minute programme will take 15 mins to capture.

mplayer -dumpstream -dumpfile tuesday.ra rtsp://rmv8.bbc.net.uk/radio4/arts/book_bedtime_tue.ra?start=45

Then you need to convert the RealAudio file to PCM WAV. This dumps it to audiodump.wav.

mplayer -ao pcm monday.ra

From here you can convert to MP3 using the LAME codec.

lame -h -v -b 128 audiodump.wav tuesday.mp3

Voila! Book at Bedtime in MP3.

#! /bin/bash

mplayer -dumpstream -dumpfile $2.ra $1
mplayer -ao pcm:file=$2.wav $2.ra
lame -h -v -b 128 $2.wav $2.mp3

Use it like:

./convert_real rtsp://rmv8.bbc.net.uk/radio4/arts/book_week_thu.ra?start=40 thursday

Comments

  1. henrik on September 2nd, 2006 at 4:24 pm

    you big nerd :)

  2. Gary Richmnd on October 27th, 2006 at 12:46 am

    I agree about the proprietary nature of the BBC music player but I think I can suggest a much easier method to record a BBC programme to your hard drive and then convert it to mp3 and then transfer it to your chosen mp3 player (ipod, iriver etc).

    Quite simply, most Linux distros come with Audacity pre-installed. If not use the usual package manager (yum, apt-get, emerge, urpmi etc) to download and install it and do the necessary configuration.

    Now, close Audacity down before opening up the BBC website page and programme of choice and tee up the item you want to record. (If you open up Audacity before this you will get an error mesage that another application is using the sound card.) Start playing the audio stream and immediately hit the record button on Audacity. Hit the stop button when the streaming audio is finished.

    Finally, in Audacity, go to ‘file’ and select export as mp3 and the file will be converted to that format and you can then drop it onto your mp3 player.

  3. Gary Richmond on October 27th, 2006 at 12:59 am

    Oops! I forgot to say that the Audacity method worked for me because I was using Firefox in Mepis which contained the necessary plugin for Realplayer out of the box! Sorry

  4. Tom on October 31st, 2006 at 6:39 pm

    The nice thing about this method is being able to script is to run at certain times.

  5. J-P on November 26th, 2006 at 6:15 pm

    I’m currently trying to put together something in Python that will do much of the hard work - following a .ram link in case it’s not a BBC stream, working off config files so it can all be cronjobbed, etc. I was originally doing the mplayer stuff in one step:

    mplayer -ao -pcm:file=/tmp/temp.wav http://...

    But that seems to be hanging at around 70-80MB in the temp.wav file for reasons I’m not quite clear on: if you’ve a reason for doing it in two steps let me know.

    Also, can you combine the 2nd and 3rd steps with a named pipe instead of a .wav intermediary? Again, it’s not something I’ve managed myself!

  6. Graceful Exits » Realplayer to mp3: a configurable Python wrapper on December 6th, 2006 at 8:55 pm

    [...] Similar solutions abound on the web: Tom Taylor has a method involving mencoder; other methods can all over the place. However, these all involve a bit of ad hoc command-line intervention, or scripts which aren’t terribly configurable. [...]

  7. harry on March 3rd, 2007 at 11:15 pm

    Fantastic script!! Works a treat and can be scheduled to run overnight when I get cheaper electricity

  8. Matt on October 2nd, 2007 at 12:19 am

    Thanks -
    I actually created a less elegant script in the same method
    it allows you to rename the show and where you want to store it on your pc.
    I am sure a true script writer could reduce this to one line.
    It is at the bottom of this posting.
    My real reason for posting now is to sort out the cookies issue now imbeded in the rtsp url
    from the bbc. I do not see a good work around - this is disastrous for us news starved yanks. Mplayer stops after about 30 seconds of a rip . poof - stymied.
    any thoughts ??
    Cheers.

    The rtsp rip script for use with mplayer
    - - - - cut below - - - -
    !/bin/bash
    #
    # rstp: stream ripper using mplayer
    #==================================================================================
    # written by matt marian # # #
    # your milage may vary #
    #=================================================================================#

    # last update October, 9 2006
    # I am sure some one can do this much more elegantly, but hey I am no script wiz
    #this version is inter-active, re-write for automated version, chron etc.

    echo “$USER, this script will guide you through the rip and later conversion”
    echo ” ”
    echo “type in the location on this pc where you want to save the file, full path”
    read -e LOCATION
    cd $LOCATION
    echo ” ”
    echo “Once the actual rip takes place, this script will appear to be silent”
    echo “Enter the name you would like the saved file to be called”
    read -e FILE
    echo “Again, once ripping starts, this script will appear to do nothing- its ok!”
    echo “type in (or paste) the URL of the stream - ending in .rm - nothing else”
    read -e URL
    echo “attempting the rip now”
    set $(date)
    mplayer -dumpfile $FILE.rm -dumpstream $URL
    echo “converting sound file to usable form”
    mplayer -ao pcm $FILE.rm
    mv audiodump.wav $FILE-$6-$3-$2.wav
    echo “all finished”
    exit
    #some tags left hanging for modifying script for multiple rips ( i.e. mon to fri BBC)

  9. matt on October 2nd, 2007 at 12:56 am

    forgive me for not seeing the update at the top
    you can just about forget I posted anything ( let alone 2 posts )
    Still troublesome with the bbc cookies though
    Mplayer is hamstrung now apparently
    Cheers
    matt - aka bonehead poster

  10. Kenny on January 20th, 2008 at 10:07 pm

    Anyone ever found a way to do this without the real time extract? 15 minutes is one thing but a 2 hour programme is a bit tiresome to rip.

  11. dude on January 20th, 2008 at 10:48 pm

    what about ripping streams on windows? and all that makes no sense

  12. dude on January 20th, 2008 at 10:53 pm

    ok lemme rephrase that lets say u found a cool radio program that works on players on windows like wmp,itunes,realplayer for example and you have an mp3 player like an ipod or a sandisk player with radio features how do you make the file compatable to the mp3 player so u can just put in the file like an ordinary mp3 file. GET IT? its easy to comprehend

  13. t. on March 12th, 2008 at 11:46 pm

    i’ve just tried your script, seems to work, however where is the 2.mp3 being saved to? i can’t seem to find it…

    please help me!

  14. David on March 21st, 2008 at 9:36 pm

    Phantastic: a cron-able script solution which avoids all the ugliness of Linux’s sound systems — thanks!
    If anyone has a wrapper-script which autonames weekly updates please post it soon.

  15. Mr. Qwerty on April 29th, 2008 at 6:29 pm

    Works the same way for windows except it is simpler and you can use environment variables to name your files. Create a batch file that cd’s to the binary file and use the following:

    mplayer -ao pcm:file=Something%date:~4,10%@%time:~0,5%.wav rtsp://something/something.rm

    Note that you have to change the way your date and time are displayed, colons and slashes are not valid filename characters. I changed mine to periods and it works like a charm.