Rip / record online radio stream
I enjoy listening to music while doing my work, but doing it with online radio is not really enjoyable as during daytime, it’s hard to listen to 128 kbps stream without buffering issue, thanks to TMNut’s Streamyx. Even if (at times) it’s ok, the bandwidth is better saved for other meaningful purposes. What I did was to create a script to dump the broadcast, run it by midnight (the time when the highways is clear for Streamyx) and stop it in the early morning. Let cron help you with this and it should make your life even easier.
In my example, I’m using 1.FM’s Channel X, and a lot more is available from www.shoutcast.com’s playlists.
(Script updated on 20070301)
#!/bin/bash
URL=http://64.62.252.130:8070
WORKDIR=/home/shakir/temp/mplayerdump
MAXDUMP=3
CURRENTDUMP=`ls $WORKDIR | wc -l`
mv $WORKDIR/current.mp3 $WORKDIR/`date +%F`.mp3
if [ $CURRENTDUMP -ge $MAXDUMP ] ; then
for i in `ls $WORKDIR | head -n $[($CURRENTDUMP-$MAXDUMP)+1]`; do
rm $WORKDIR/$i
done
fi
mplayer -dumpstream $URL -dumpfile $WORKDIR/current.mp3
#ffmpeg -i $URL -ab 128 $WORKDIR/current.mp3
11 Responses to Rip / record online radio stream
khairul
February 27th, 2007 at 1:43 am
dis is kewlll…
shakir
February 27th, 2007 at 1:50 am
Thanks, and I’m waiting for someone to comment on the legal issue of doing this
mysurface
February 27th, 2007 at 2:00 pm
Cool! Mplayer really capable of doing a lots more.
What kind of file format is the dump file been recorded? Can we converted into mp3?
shakir
February 28th, 2007 at 3:58 am
It’s saved as raw stream, and I haven’t tried any player other than mplayer to play the file. Haven’t tried converting it too, but I guess mencoder can help with that.
mysurface
February 28th, 2007 at 2:32 pm
Haha, just put as .mp3 will do, I have tried.
mplayer -dumpstream $URL -dumpfile $DUMPDIR/current.mp3
by the way, you can use ffmpeg for dumping too, and it is much more better, because the size of the file is visible to you.
ffmpeg -i $URL -ab 128 current.mp3
shakir
March 1st, 2007 at 12:45 am
Thanks for pointing these out. And talking about size, the original script should be updated to delete old dumps as one night’s dump can take around 300MB for a 96kbps stream.
#!/bin/bash
URL=http://64.62.252.130:8070
WORKDIR=/home/shakir/temp/mplayerdump
MAXDUMP=3
CURRENTDUMP=`ls $WORKDIR | wc -l`
mv $WORKDIR/current.mp3 $WORKDIR/`date +%F`.mp3
if [ $CURRENTDUMP -ge $MAXDUMP ]
then
for i in `ls $WORKDIR | head -n $[($CURRENTDUMP-$MAXDUMP)+1]`
do
rm $WORKDIR/$i
done
fi
#mplayer -dumpstream $URL -dumpfile $WORKDIR/current.mp3
ffmpeg -i $URL -ab 128 $WORKDIR/current.mp3
Vishal
July 25th, 2007 at 5:24 pm
how about if you want to just record one show from say 10:00 am to 12:00 pm for 2 hours? Can you help with that please..
thanks,
vishal
Donneker
July 26th, 2007 at 1:24 am
Hi, I dunno if you could use this, but I have modified an bash script which I found on the Internet myself. Its called radio_rip. I modified it best for my needs, and it saves bandwith because you can hear and record music just with one single connection to the streaming server. because of the base how its working, it has some buffer seconds, which perhaps could be enough for your internet connection too. I would advise that you try it, and perhaps you could mail me how you found it. See http://www.donneker.de/projects/radio-rip
hf & gl
shakir
July 26th, 2007 at 2:16 am
Vishal: You can take a look at cron and see what you can do to start the script. As to stop it, I normally have a killall command in my cron entry, or to be based on the mplayer’s man page, you’re supposed to be able to do this too:
-endpos 56
Stop at 56 seconds.
-endpos 01:10:00
Stop at 1 hour 10 minutes.
Donneker:
I’ve downloaded and tried you script + streamtuner, and I must say it’s a good one. My script however is meant for a simple purpose and I hope it serve its purpose well
KwangErn Liew
July 27th, 2007 at 8:49 am
For legalties, it’s not a problem. RIAA even confirmed it.
http://hypebot.typepad.com/hypebot/2007/07/riaa-admits-str.html
A
August 5th, 2008 at 10:07 pm
this script Stop the record.
only required adjust the recording time via the crontab
#!/bin/sh
aa=`ps -A | grep mplayer | awk ‘{print $1}’`
kill -9 $aa