Categories
General

crontab + wget = Tivo for internet radio

Let’s say your favorite radio station has an MP3 stream. Unfortunately, your favorite radio show on that station is on at some odd hour. Or you’re just scatterbrained and forget to tune in. You desperately need to record the show so you can listen to it whenever you’d like. Using cron, wget, and a little shell script it’s pretty easy.

Find the stream address

At my favorite station, KEXP, clicking an MP3 stream gives you a .pls file, which contains the stream address. Normally, you’d open this in an audio client such as xmms and listen away. Instead, download the .pls file so you can view the stream address.

Write a script

Here’s an example bash script that records a show with wget, using the date to make a unique name for the show. URL is the stream address you found earlier. LPath is the path where you want to put your recorded shows.


#!/bin/bash

Date=$(date +%F-%k-%M)
URL="http://internet-radio-station.net:8000/"
LPath="/home/joe/music/radio_shows/"

/usr/bin/wget $URL -O ${LPath}radio_show-${Date}.mp3

Save the script to your bin folder as something like “radioshowrec” and test it out – run it for a few seconds, stop it, then listen to the resulting mp3 file.

Setting up the cron jobs

First, make sure your user can use cron. I did this by switching to superuser mode and making an /etc/cron.allow file with my username in it.

Next edit your crontab file by typing “crontab -e” and add a pair of lines like this for each show you want to record:


00 12 * * 1 /home/joe/bin/radioshowrec
00 13 * * 1 /usr/bin/killall wget

The first line starts the recording at noon every Monday. The second line stops it at 1 pm. It will actually kill all of the wgets that might be running – if you plan on having more than one going at once you should figure out a smarter way to stop the recording.

Since the above script makes files with unique names, the files will pile up after a while. Personally, I just want to listen to the most recent show, so I leave the date part out of the script, overwriting the old file every week.

Avatar photo

By isaac

I like cats. he/him