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-18 05:24 pm (UTC)
From: [identity profile] featheredfrog.livejournal.com
'way too much work. Wanna sliptime a stream? try a crontab entry like...

59 8 * * 3 curl -m 7320 -o shickele_mix.mp3\
http://pubint.ic.llnwd.net/stream/pubint_wamc

Which traps the 62 minutes following 20:59 on tuesday nights...

This presupposed the stream is in .mp3 format. Although it will save in whatever form arrives, and can be lame-ed later, if you like.

conceivably you could output to stdout and pipe to lame, as well, if you want the conversion inline...

...come to think of it, tuesday is 2, isn't it?

Date: 2006-07-18 05:26 pm (UTC)
From: [identity profile] featheredfrog.livejournal.com
59 8 * * 2 curl -m 7320 -o outputfilename streamurl
From: [identity profile] elfs.livejournal.com
Heh. Well, seven lines of hackery (and ten extra lines of professionalism) get me a stream in just about any damn format I want, not just MP3. I suppose I should have thought of curl first, but wget's been my baby forever.

Date: 2006-07-19 05:50 am (UTC)
From: [identity profile] ewhac.livejournal.com
Hmm, mkfifo. Didn't know about that one; thanks.

Date: 2006-07-19 06:11 pm (UTC)
From: [identity profile] elfs.livejournal.com
Useful for all sorts of things! Along with creating pipes for programs that can't write to stdout, it can also be used to concatenate a split file on the fly without having to chew up your diskspace-- useful for previewing a binary download from Usenet:
mkfifo porn.mpg
cat dirtymovie.mpg.??? > porn.mpg
mplayer porn.mpg

You can't seek back in the stream this way, but you can seek forward, so if you've got parts one through five you can get a good idea if you want to burn bandwidth downloading parts six through ninety-nine. It's faster, saves diskspace, and saves wear-and-tear on the drive.

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.)

Date: 2006-07-20 09:11 pm (UTC)
From: [identity profile] woggie.livejournal.com
Thank you for something new to study. :)

It appears I'm going to have to learn scripting language for use in batch files like this one. Every set of instructions I've ever seen for making Linux do what you want seems to be written in it.

Screamer Radio for Windows

Date: 2006-12-08 01:49 am (UTC)
From: (Anonymous)
Hi.

Perhaps this will help for those using Windows.

http://www.screamer-radio.com/

:-)

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 01:25 pm
Powered by Dreamwidth Studios