Recording Streaming Radio (improved)

Save this script as 'radio'
#!/bin/bash
# $1 = URL
# $2 = Title
set -e
TMP="/tmp/radio-`perl -le 'print localtime()'`"
mkfifo $TMP
DATE=`date +%Y-%m-%d`
MP3="$HOME/Desktop/$2 $DATE.mp3"
lame $TMP -o "$MP3" -V 2 --tt "$DATE" --tl "$2" --ta "Radio" --ty "`date +%Y`" --add-id3v2 --pad-id3v2 --ignore-tag-errors --quiet &
LAME_PID=$!
mplayer -playlist "$1" -vc null -vo null -prefer-ipv4 -bandwidth 8000000 -ao pcm:fast:waveheader:file=$TMP &
MPLAYER_PID=$!
trap "kill $MPLAYER_PID; echo 'killed recording'; exit" HUP INT TERM
trap "kill $LAME_PID; rm $TMP; exit" EXIT
wait $MPLAYER_PID
Then run it weekly like this:
radio 'http://www.bbc.co.uk/radio/aod/shows/rpms/radio1/breezeblock.rpm' 'Mary Anne Hobbs: Breezeblock'
or like this:
radio 'http://icecast.commedia.org.uk:8000/resonance_hi.mp3.m3u' 'Resonance FM'

To automatically add the MP3 to iTunes (on Mac OS X) when it's complete, add this line to the end of the script:

osascript -e "tell application \"iTunes\" to add POSIX file \"$MP3\" to playlist named \"Radio\""