Updated Dec. 24, 2005: Fix code for MPlayer command, include Ogg Vorbis encoding, include regexp matching to download partial programs, include special code for OTM. And probably a few bug fixes.
Updated Mar. 21, 2005: Now record multiple NPR streams to increase speed. Also, a few minor changes in default behavior from the previous version. Sorry for any inconveniences, but I'm just a part-time geek, not a reliable developer. If you use these scripts, please donate to National Public Radio.
I live in the Netherlands and commute over an hour to work each day. I really missed listening to NPR on my way to work and so I wrote some scripts to stream NPR's news programs overnight and put them either on a CD or an mp3 player.
My solution is perhaps idiosyncratic. I wrote it for my personal use and not for a broad userbase. There is a more complete HOWTO and set of tools for timeshifting radio programs at Linux Radio Timeshift HOWTO, but maybe someone will find my script useful, too. Anyway, when I started looking into this problem, that HOWTO wasn't around yet.
NPR Podcast news: NPR is currently podcasting some of their articles. It should be fairly simple to just grab the podcast from the source, but you won't get the entire broadcast of ATC, say. Check out NPR's Podcast Directory for details.
The main script is
npr-grabber.sh. This script uses
mplayer to stream
the program and save the streams as WAVE files (exception: See
OTM details). Then it either burns a CD or
converts the WAVE file to MP3s. It records multiple streams at
once --- see below.
The basic usage is
npr-grabber.sh [options] PROGCODE
PROGCODEis NPR's program code for the program. Here are the codes I use regularly. They must be capitalized.
|All Things Considered||ATC|
|Weekend Edition Saturday||WESAT|
|Weekend Edition Sunday||WESUN|
|On The Media||OTM|
Options include the following.
||Fetch the program for the given date.|
||Choose alternate root directory.|
||Create MP3s (default).|
||Do not create MP3s.|
||Do not delete old files.|
||Maximum number of streams recorded at once (Default: 10).|
||Just one stream at a time|
Audio files are saved in
/storage/multimedia/npr/PROGCODE, and MP3s in the
mp3. After all the MP3s are created,
they're copied to
/mnt/stick/PROGCODE. I mount my
MP3 player at
mplayer does a good job saving streamed Real
audio streams, but there is one annoying problem. It takes some
mplayer notices it has reached the end
of stream --- a minute or two. This isn't a problem for me, since
I run the script as a cron job. Here are the relevant entries for
my crontab (I create both MP3s and an audio CD for the car).
You'll need to check when the shows are available for you. They become available shortly after they finish broadcasting on the West Coast.
00 4 * * * /home/jesse/bin/npr-grabber.sh -m -d yesterday ATC >/storage/multimedia/npr/ATC/log 00 18 * * mon-fri /home/jesse/bin/npr-grabber.sh -m ME >/storage/multimedia/npr/ME/log 00 19 * * sat /home/jesse/bin/npr-grabber.sh -m WESAT > /storage/multimedia/npr/WESAT/log 00 19 * * sun /home/jesse/bin/npr-grabber.sh -m WESUN > /storage/multimedia/npr/WESUN/log
When you run the script, it deletes any old audio files from
previous shows (unless you use the
-a flag). So if
you want to save a program, move it out of
The latest version of
npr-grabber.sh fetches ten
streams at once by default. This means that an hour and a half
program can be fetched in under thirty minutes, typically
(including making the mp3s).
You may want to test this a time or two to see if the result
works well for you and adjust the number fetched by
-n. There seems to be a limit in the number of
streams that can be recorded all at once --- when I tried twenty,
most of the streams were unlistenable screeches. No more than one
lame is run at a time, since multiple
versions slow the process rather than speed it (
is bloody well CPU intensive).
Each instance of mplayer is put into its own
screen, so you can keep tab of how the streaming and
encoding is going via
On The Media is podcast-friendly. They provide an mp3 of each show available for download at their homepage, so you don't really need my script to listen to this program.
However, I didn't want one large mp3 of all the segments. I
prefer each segment in a different file. So I wrote a simple
script to do this (
otm-grabber.sh) and altered
npr-grabber.sh to use
otm-grabber. otm-grabber fetches the mp3s for each segment and
changes the id3 tags slightly. It is very fast, since it does not
use streaming at all.
Here are all of the scripts I use. You should have a look at them and see if any directories, etc., need to be changed. If you have any questions, just ask.
||The main script, described above|
||Helper that grabs and encodes individual segments.|
||Helper for grabbing individual segments of On The Media.|
||A simple script for playing the streamed program directly from the hard drive.|
||A simple script for writing the audio CD.|
If you use this script, please support National Public Radio. Please donate to your local radio station. If you haven't a local station, consider donating to WDUQ (my old Pittsburgh station), WHYY (Philadelphia, home of Fresh Air), WBEZ (Chicago, home of This American Life) or KOSU (Stillwater, OK, the first NPR station I listened to).
mplayer -cache 512 -playlist http://184.108.40.206:80/listen.pls
mplayer -cache 512 -playlist http://wnyc.org/stream/wnycfm.pls
mplayer -cache 512 -playlist http://www.wbur.org/listen/feed/shoutcast.pls
It is very easy to capture mp3 streams for later listening, whether you use MPlayer or other software. This is a very nice service!
mplayer -cache 512 http://pubint.ic.llnwd.net/stream/pubint_wgbh