Recording Internet Radio Broadcast Streams with Damn Small Linux - Part 1

Well my DSL server has been running pretty good for a while now so it must be time to try and break it.

Here's my new passion.... I've been listening to radio stations that broadcast over the internet. You know, the streaming audio type of stuff. I can listen to classical from KUSC.org or jazz/folk/bluegrass from WMUB.org A problem comes up sometimes when I want to listen to a particular radio show but because of the time-zone differences or my schedule I'm not able to be at the computer to listen to it.

Back in the days before I pushed electrons around I had a stereo tape deck that could do timed recordings from AM/FM radio broadcasts. Basically I want to do the same thing but with internet radio. There might be a bunch of programs out there on the market (or maybe in myDSL extensions...I really need to look in there.) to do this but I didn't find any in my not-so-intensive 30 second search, so I decided to build one myself.

Here's what you'll need besides the basic DSL system.
1) Mplayer or Mplayer-xfree86 from the multimedia section of the myDSL extentions
2) Internet connection that works with DSL
2) Storage space for the recorded audio. For an MP3 file you can figure on about 10 meg of storage for every hour of recording. This can vary by radio station.
3) An average amount of tech skill and patience....

Let me preface this with one comment. I have no idea if it is legal to record internet radio stations. If it's not legal where you live then don't do it. I treat it like taping a TV show with my VCR. If it's for my own non-profit use then I think it should be OK.

Lets pick a sample station. I'm going to use www.wmub.org. If you go to their webpage, halfway down on the left, you'll see that they offer online listening in three formats (like lots of stations). They have Windows Media Player format, Real Player format, and MP3 format (some stations will call this Winamp format). I'm going to select the MP3 format. I'd suggest that you click on it and make sure you can hear the broadcast before you go to much further. If you can't hear the broadcast then trying to record it isn't going to work too well.

At this point you should have downloaded the Mplayer extention from the Multimedia section of the myDSL library. You should also have verified that WMUB will play on your machine. By default XMMS will play the WMUB broadcast, that's OK. While playing/recording you need to be connected to the internet.

In order to plug into the broadcast stream we need to determine where the broadcast is coming from and store that into an Mplayer 'playlist'. Go to the www.wmub.org web page. Right-click on the (left side of page) Listen Online.... MP3 link and select Save Link As... save the file to your home directory. The name should be something like wmub.pls. Use emelFM view/edit to view the file you just saved. You'll notice the playlist contains two files. The first one is a recorded message welcoming you to WMUB and asking for your support. The second file is the actually live broadcast stream. The second file is the one you want to use as your input to Mplayer. Currently the name of the second file is: http://pubint.ic.llnwd.net/stream/pubint_wmub.

Create a text file in your home directory called wmubPlaylist.txt, place the name of the broadcast stream (http://pubint.ic.llnwd.net/stream/pubint_wmub) in it. Save and close wmubPlaylist.txt.

wmubPlaylist.txt looks like:


http://pubint.ic.llnwd.net/stream/pubint_wmub

Now we create a script to run Mplayer in recording mode. It tells Mplayer what to record, what format to record it in, and where to put the recorded file. We're going to record the raw stream since it's in MP3 format. The script I created looks like this:


#!/bin/sh
#
# script to record MP3 broadcast stream
# The command is all on one line ending with a semi-colon
#
/opt/mplayer/mplayer -playlist /home/dsl/wmubPlaylist.txt -dumpstream -dumpfile /home/dsl/WMUB_$(date +%m%d%H%M).mp3 -vc dummy -vo null ;

#
# If your station does not have an mp3 feed you can use the mplayer command below to capture the broadcast in WAV format. It will be very large.
# /opt/mplayer/mplayer -playlist /home/dsl/wmubPlaylist.txt -ao pcm -aofile /home/dsl/testListen.wav -vc dummy -vo null ;


Wordwrap may make this script look mangled. All the lines are comments (they start with #) except the line that starts with /opt/mplayer/mplayer. That should all be on one line up to and including the ending semi-colon.

On my setup Mplayer was put in the /opt/mplayer directory. You may need to modify this for your setup. Change the -playlist parm to point to the file you created with the WMUB feed in it.. Change the -dumpfile to be the name of the file where you want the recording stored. My example will store the file in the home directory of dsl user with a name of WMUB_ followed by the two digit month, two digit day, two digit 24-hour clock, two digit minute and ending with a dot mp3.

Save the script as recordWMUB.sh in the dsl home directory and make it executable. I do that by using emelFM and right-clicking the filename and selecting properties.... permissions and clicking all the Execute buttons. Some people can remember the linux command line for doing it but I never get it correct so I use emelFM. You have to go back and make it executable each time you edit/save the script.

When I do a test run this is what I see in the console:


dsl@DSL22rc1:~$ recordWMUB.sh
MPlayer 1.0pre6-3.3.1 (C) 2000-2004 MPlayer Team
CPU: Intel Celeron 2/Pentium III Coppermine,Geyserville (Family: 6, Stepping: 3)
Detected cache-line size is 32 bytes
CPUflags: MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 0
Compiled with runtime CPU detection - WARNING - this is not optimal!
To get best performance, recompile MPlayer with --disable-runtime-cpudetection.
Linux RTC init error in ioctl (rtc_irqp_set 1024): Permission denied
Try adding "echo 1024 > /proc/sys/dev/rtc/max-user-freq" to your system startup scripts.
Playing http://pubint.ic.llnwd.net/stream/pubint_wmub.
Resolving pubint.ic.llnwd.net for AF_INET...
Connecting to server pubint.ic.llnwd.net[68.142.72.13]:80 ...
Name : WMUB Live Stream
Website: http://www.wmub.org
Public : no
Bitrate: 24kbit/s
Cache size set to 320 KBytes
Connected to server: pubint.ic.llnwd.net
Stream not seekable!

To stop recording use CTRL-C and you'll see:

MPlayer interrupted by signal 2 in module: dumpstream
dsl@DSL22rc1:~$

Use emelFM and check in the dsl home directory and see if you have a WMUB_ file. Double click on it and it should start playing. If it doesn't then there is a problem with some part of the process. Check the console output for errors. The script for typos. The playlist for typos. Make sure your internet connection was available. Check to see if Mplayer will play any file for you.

That's it for Part 1. In Part 2 we'll automate the task of recording.