Monday, December 17, 2007

I listen to NPR off-and-on throughout the day. But I rarely listen to live radio — it almost entirely comes from podcasts that I download with iTunes. I want to listen to what I want, when I want, and be able to re-arrange the order of upcoming shows in any arbitrary order I please. But the two main daily shows that I’d like to listen to, Morning Edition and All Things Considered, don’t offer podcasts. I could play the shows directly from npr.org, but then I obviously can’t listen on my iPod, and have less control over how I use it.

So I did some searching and a do-it-yourself approach is far easier than I’d imagined thanks mainly to an open source program called streamripper. Binaries are available for Mac, Linux and Windows. It’s a command line program, so you have to give it some parameters and set it to a schedule, so I can record Morning Edition from my local affiliate, KUOW, by running this command at 5 a.m. each weekday:

streamripper http://128.208.34.80:8002/ -a morning_edition.mp3 -s -d /data -l 7200

To write id3 metadata tags to our new file (used by mp3 players like iTunes), I downloaded id3v2 and gave it the following command:


id3v2 -a “NPR” -t “Morning Edition” -y `date +%Y` -g “Podcast” morning_edition.mp3

I wrapped these commands in a shell script to make it more generic. It saves each show as a separate file such as “Morning_Edition_2007-12-14.mp3”. This will work on the Mac/Linux, but a similar .bat file will need to be created for a Windows environment.

#!/bin/sh

# Config variables
MINUTES=120
ARTIST=”NPR”
DESC=”Morning Edition”
DIR=”/data/podcasts”
GENRE=”Podcast”
SRC=”http://128.208.34.80:8002/”

# Script starts here
DATE=`date +%Y-%m-%d`
STUB=`echo “$DESC” | awk ‘{gsub(/\ /,”_”);print}’`
FILENAME=$DATE\_$STUB.mp3
/usr/bin/streamripper $SRC -a $FILENAME -s -d $DIR -l `expr $MINUTES \* 60` -r —quiet
/usr/bin/id3v2 -a “$ARTIST” -t “$DESC” -y `date +%Y` -g “$GENRE” $DIR/$FILENAME

I named the script “morningedition.sh” and put it in my crontab to fire up weekdays at 5a.m.:


0 5 * * 1,2,3,4,5 ~/morningedition.sh

And voilĂ , I have my podcast. Pair this with other media sources and you can record any NPR show you like.


Search

Syndication

RSS: .91 / 1.0 / 2.0