Hack 81. Rip Streaming Audio
Streamripper lets you rip the live streaming audio station of your choice directly to MP3 for later listening .
Streaming audio has allowed a number of people to easily broadcast not only their favorite music tracks, but also other types of radio shows. Instead of being broadcast all day long, some shows are broadcast only at certain times of the day. If you aren't at your computer when the show is broadcast you'll
streamripper
is a simple but powerful command-line application that allows you to record streaming audio directly to local MP3 files. To install
streamripper
, see if your distribution has already packaged it,
To use streamripper , simply pass it the URL to your streaming audio station in a console window: $ streamripper http://69.56.219.92:8072
By default,
streamripper
will create a directory named after the stream in the current directory and then start storing the streaming content as MP3s within an incoming directory. When a file is complete,
streamripper
will move it up from the incoming directory to the stream's main directory. Each file is named after the artist and track metadata that
streamripper
grabs from the audio stream. You can leave
streamripper
running as long as you wish (provided you have enough hard drive space), and it will continue to grab and store MP3s in the stream's directory. Provided you have enough
The
streamripper
defaults are suitable for standard uses, but
streamripper
also allows you to configure everything through command-line options. For instance, the
-d
argument
By default, MP3s that
streamripper
saves are titled after the artist and track
4.10.1. Schedule RecordingsDue to its command-line nature, streamripper is ideal for scheduling recordings with at or cron . The -l argument lets you configure a number of seconds for streamripper to record before it automatically exits. Combine this with the -q and -P options and you can easily create an archive of your favorite radio show. For instance, one stream I like to listen to only plays between noon and 6:00 P.M. PST Thursday through Saturday. I created the following script called streams to record it: #!/bin/sh # rips from Punk FM (http://punkfm.co.uk) # this stream is broadcast from noon to 6pm PST Thu-Sat URL='http://69.56.219.92:8072' DAY=`date +%F-` streamripper $URL -d /mnt/audio/mp3/streams -q -P $DAY -l 21720 --quiet &
This script rips the URL into my
/mnt/audio/mp3/streams
directory, makes sure that the tracks are named sequentially with the
-q
argument, prepends the current day's timestamp with the
-P
option, and tells
59 11 * * 4-6 / home/greenfly/bin/streams
This line will execute the script at 11:59 A.M. on Thursday, Friday, and Saturday. Read the
crontab
4.10.2. Listen to Streams as They Are Ripped
Another nice feature of
streamripper
is the ability to create a relay server for streams as they are being ripped. The
-r
option tells
streamripper
to create a relay server on port 8000, or you can specify a different port to use as an argument. If port 8000 isn't available,
streamripper
will try to use higher and higher ports until it finds one it can use. Then you can point your music player at port 8000 (or the port you configured) on that machine either from the same computer (
http://localhost:8000
) or over the network (
http://ip_address:8000
). By default
streamripper
will only allow a single connection to this relay server, but you can pass the
-R
number argument to it to allow a specified number of
$ streamripper URL -r -R 3 If I wanted to allow three clients to connect to the stream my bash script recorded, I would change the command to the following: streamripper $URL -d /mnt/audio/mp3/streams -q -P $DAY -l 21720 --quiet -r - R 3 & 4.10.3. Track Detection
streamripper
automatically
$ streamripper URL --xs_offset=3000 Alternatively, if a track has three seconds of the next track at the end, you can set the offset to a negative amount: $ streamripper URL --xs_offset=-3000 If you notice that streamripper contains a various amount of previous or following tracks, but it isn't a constant value, you can also have it create a number of seconds of padding around each track so that you can go back later and edit the MP3 by hand. For instance, to add two seconds of padding before the split point and three seconds after each split point, type: $ streamripper URL --xs_padding=2000:3000 You can also combine the following two options. If for instance, each track contains a number of seconds of the previous track, but it varies between two and six seconds, you can set the split offset in the middle of the variation, or four seconds, and then create a padding of two seconds before and after the split: $ streamripper URL --xs_offset=4000 --xs_padding=2000:2000 |