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

Posted on 27.02.2007 and categorized under Information Insemination

11 Responses to Rip / record online radio stream

khairul

February 27th, 2007 at 1:43 am

Avatar

dis is kewlll… :)

shakir

February 27th, 2007 at 1:50 am

Avatar

Thanks, and I’m waiting for someone to comment on the legal issue of doing this :D

mysurface

February 27th, 2007 at 2:00 pm

Avatar

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

Avatar

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

Avatar

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

Avatar

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

Avatar

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

Avatar

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

Avatar

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

A

August 5th, 2008 at 10:07 pm

Avatar

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

Comment Form


  • peja: Ni projek utk sapa ni bro? dah ada org berminat nk beli blom?
  • rizal: bro sy nak nik lpi 101 tp xtau kat ner nak mik dan mcm ner mik.. kalo leh bg taw..mcm ner nak mik exam lpi.. kat ner nak mik.. tlg email kat sy bro t
  • gbelbe: Hi! good job! I'm using the huawei eg162 with china mobile and I had the same problem. If i boot with the modem plugged in it worked, but anytime i t
  • Michael: You guys out there that post this crap should learn how to write. You are all writing to each other. You all already know what it is your talking ab
  • WAN MAN: Memang terliur gua tengok bro punya photos....gua baru bercadang nak beli D90...tapi bajet ade sikit kurang....kena kumpul dulu..... Tapi gua tengok

Twitter