How to record online radio streams with Streamripper on a Linux (Raspberry Pi) system

This isn’t a blog post as much as it is just some notes on how I got streamripper working the way I want to on my Raspberry Pi “AlRadio” project. That project is a little like a radio in that it plays FM radio stations, but it also plays live radio streams, makes and plays recorded radio streams, and plays podcasts.

Streamripper in production

I installed streamripper with apt-get like this:

$ sudo apt-get install streamripper

This is the script I use to make recordings of the 104.3 FM radio station here in the Denver area on my AlRadio system:

#!/bin/sh

date=`date +"%Y_%a_%b_%d_%H%M%P"`

url=http://4533.live.streamtheworld.com:80/KKFNFMAAC_SC
output_filename=104_3.${date}

duration=3600

output_dir=/var/www/radio/data/recordings
cd $output_dir

streamripper $url -d $output_dir -l $duration -a $output_filename -o always

When this script is run via crontab entries, it creates recorded stream files that look like this:

104_3.2014_Sat_May_24_1200pm.aac
104_3.2014_Sat_May_24_1300pm.aac
104_3.2014_Sun_May_25_1200pm.aac
104_3.2014_Sun_May_25_1300pm.aac

My crontab entries for this 104.3.sh script look like this:

# 104.3 (afternoon guys)
0 12 * * * /var/www/radio/data/recordings/104_3.sh  > /var/www/radio/logs/104_3.log 2>&1
0 13 * * * /var/www/radio/data/recordings/104_3.sh  > /var/www/radio/logs/104_3.log 2>&1

Streamripper notes

Everything below this point are notes that I made as I was learning how to use streamripper:

finding a stream
----------------

"The easiest way to get started is to find the URL of a stream you want to rip. 
Usually I find the URL by loading it up in Winamp or XMMS and querying for the source URL."

commands
--------

# specify directory
streamripper URL -d recordings

# don't create a directory for each stream
-s 

# add sequence number to output file
-q

# suppress the creation of the stream folder by adding -s
streamripper URL -d OutputFolder -s

# run for an hour
-l 3600

# If -D is used, the options -s and -P will be ignored.
# name files with date and time (per exec)
-D %d

%S   Stream
%A   Artist
%T   Title
%a   Album

-a [pattern]
# Sometimes you want the stream recorded to a single (big) file 
  without splitting into tracks. The -a option does this. If you use -a without 
  including the [pattern], a timestamped filename will automatically be used.

-A
Don´t create individual tracks.
The default mode of operation is to create one file for each track. 
But sometimes you don´t want these files.
Using the -A option, the individual files for each track are not created.

# user agent
-u "FreeAmp/2.x"

-o (always | never | larger | version)
Overwrite tracks in `complete` directory. When streamripper rips tracks they are put into 
the incomplete directory until they are finished. Normally, they are then moved into the 
complete directory. However, when the track is already there, can use this option to tell 
streamripper what you want to do.

--quiet
Quiet operation. Don´t write any text to the console, except error messages

--stderr
Write output to stderr instead of stdout

tests
-----

streamripper http://4533.live.streamtheworld.com:80/KKFNFMAAC_SC -d recordings -l 5 -s -q -D %S%d

# creates "recordings/foobar/incomplete/ - .aac"
streamripper http://4533.live.streamtheworld.com:80/KKFNFMAAC_SC -d recordings -l 5 -s -q -D foobar

streamripper http://4533.live.streamtheworld.com:80/KKFNFMAAC_SC -d recordings -l 5 -D 104_3

# creates "recordings/104_3.aac"
streamripper http://4533.live.streamtheworld.com:80/KKFNFMAAC_SC -d recordings -l 3 -D 104_3 -a 104_3

date=`date +"%Y_%m_%d"`
streamripper http://4533.live.streamtheworld.com:80/KKFNFMAAC_SC -d recordings -l 3 -D 104_3.${date} -a 104_3.${date}

Streamripper help and useful URLs

  • http://streamripper.sourceforge.net/tutorialconsole.php
  • http://ubuntuguide.org/wiki/Streamripper

Don’t forget to view man streamripper for more help.

Summary

If you are interested in using streamripper to make recordings of online radio streams, I hope you find these notes and examples helpful.