elfs: (Default)
[personal profile] elfs
Tonight, my local NPR affiliate is playing Selected Shorts, and Leonard Nimoy will be doing the reading. I want to listen to it, but Selected Shorts isn't available in a free archive and I don't want to be up at that hour. The problem was simple: how do I capture the audio in a podable format?

My solution works for Linux geeks.

Well, Mplayer will play many audio streaming formats, including many MS and Quicktime formats, but it dumps to a file. Also, I want it in MP3 format, and Lame will handle that, but how do I get the file from Mplayer to Lame without a humungous wave file in the middle? Well, Linux has named pipes, so I created one of those, and then Mplayer dumps to it, and Lame picks the stream out of it. I put both of those processes in the background in the right order, then wait for the correct interval and kill the Mplayer process. Lame detects the pipe closure and cleans up the MP3 output appropriately.

Obviously, for this to work, you need Mplayer, Lame, and I strongly recommend Delay, a replacement for the traditional sleep command with a lot of nifty features. If you don't have it, you can edit the file and substitute sleep for Delay.

Posting code to LJ is notoriously difficult, but let's see if I can't get it to behave now. If you use this code, you are responsible for its use, no warranties, released under the GNU Public License, all that. You are also responsible for discovering your local NPR affiliate's data stream (which can usually be uncovered by downloading one of the 'listen now' links and examining the source code), and for using it responsibly.

 #!/bin/bash

INTERVAL="2:00"
OUTFILE="output.mp3"
AFFILIATE="YOUR AFFILIATE'S MEDIA ADDRESS GOES HERE"

if [ "X$1" == "X-h" -o "X$1" == "X-u" ]; then
echo "Usage: $0 [OUTFILE] [INTERVAL]"
echo "Default outfile is output.mp3"
echo "Default interval is one hour."
exit
fi

if [ "X$1" != "X" ]; then
OUTFILE=$1
fi

if [ "X$2" != "X" ]; then
INTERVAL=$2
fi

rm -f /tmp/nprrip.$$
mkfifo /tmp/nprrip.$$
lame /tmp/nprrip.$$ $OUTFILE 2> /dev/null &
mplayer -really-quiet -ao pcm:file=/tmp/nprrip.$$ $AFFILIATE &
delay $INTERVAL
kill %2
rm -f /tmp/nprrip.$$

Date: 2006-07-20 02:13 am (UTC)
From: [identity profile] http://users.livejournal.com/_candide_/
Since "Selected Shorts" is produced by WNYC, consider looking over at www.wnyc.org for podcasts of it. WNYC is pretty good about podcasting its programs.

(Although, in the case of "Selected Shorts", they may not be able to due to the gobs and gobs of permissions they'd need to get just to legally podcast one episode. Have a look at their website, though, & see.)

Profile

elfs: (Default)
Elf Sternberg

December 2025

S M T W T F S
 12345 6
78910111213
14151617181920
21222324252627
28293031   

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Dec. 31st, 2025 10:27 pm
Powered by Dreamwidth Studios