Streaming Radio to mp3

When I worked in Manchester, I’d listen to Allan Beswick’s lunchtime radio show on BBC Radio Manchester (95.1 FM). The BBC streams Beswick’s show online, so I can still listen here in Wisconsin, but what I really wanted to do was get the show as a podcast so I could listen to it wherever I was.

The BBC provides a lot of good radio shows as podcasts, but not the one I’m interested in. I did some research and found a way to make my own podcasts from the BBC’s streaming audio using my PC running Ubuntu Linux.

The media player MPlayer can be given this command to record an audio stream to a file:

mplayer -playlist http://www.bbc.co.uk/radio/aod/shows/rpms/manchester/allan_beswick_manc.rpm -ao pcm:file=”/home/dan/allan_beswick/beswick.wav” -vc dummy -vo null

The URL used above was retrieved from the BBC iPlayer using Firefox. I accessed the Page Info (right-click menu) of the iPlayer page that played the streaming audio I wanted, selected the Media tab and found the URL as an embed in the list.

To explain the switches used in that command, -playlist is used because the URL retrieved from the BBC iPlayer isn’t a direct link to the audio stream we want to capture. When I looked into recording streaming audio, I found that streaming audio services like this normally provide audio players with a file containing a playlist of audio streams. In this example, the playlist file is located at the URL shown in the command above.

-ao is used to specify the output file for the stream.

-vc dummy and -vo null prevent MPlayer from attempting to find and play any video content, as there isn’t any.

Running the command will cause MPlayer to output some information about the steam to the terminal. I’ve trimmed down the output here to show a few interesting parts.

Resolving www.bbc.co.uk for AF_INET…
Connecting to server www.bbc.co.uk[212.58.253.71]: 80…

Playing rtsp://rmv8.bbc.net.uk/england/radiomanchester/aod/allan_beswick.ra?BBC-UID=84076f367e62512a2b98bcba80b0972372b2525bb0b0b154048f98b17feb5665_n&SSO2-UID=.

This is the audio stream specified in the playlist file at the URL given to MPlayer.

Resolving rmv8.bbc.net.uk for AF_INET…
Connecting to server rmv8.bbc.net.uk[212.58.252.5]: 554…

REAL file format detected.
Stream description: audio/x-pn-multirate-realaudio logical stream
Stream mimetype: audio/x-pn-realaudio
Clip info:
name: Allan Beswick
author: BBC Radio Manchester
copyright: (C) British Broadcasting Corporation 2008

Some information about the audio stream.

Video: no video
Starting playback…
A: 112.9 (01:52.9) of 6861.0 ( 1:54:21.0) 90.0% 0%

A progress indicator. MPlayer is 1 minute and 52 seconds into the stream here.

MPlayer will output a wav file. The following line will use lame to convert the file to an mp3 file.

lame -h /home/dan/allan_beswick/beswick.wav -o /home/dan/allan_beswick/beswick$(date +%m%d%Y).mp3

I put those commands into a bash script that runs as a cron once daily between Monday and Friday and I have Allan Beswick’s radio show ready to load onto my iPhone once a day.

The bash script I use, shown below, adds dates to the mp3 files it produces for organization.

#!/bin/sh

mplayer -playlist http://www.bbc.co.uk/radio/aod/shows/rpms/manchester/allan_beswick_manc.rpm -ao pcm:file=”/home/dan/allan_beswick/beswick.wav” -vc dummy -vo null;
lame -h /home/dan/allan_beswick/beswick.wav -o /home/dan/allan_beswick/beswick$(date +%m%d%Y).mp3;
rm /home/dan/allan_beswick/beswick.wav;