Save mp3 radio streams to file

Posted on 04/11/10 No Comments

I use my HTC Hero to listen to music everyday while I walk to and from work. Who doesn’t, right?

Unfortunately my favorite station (electricFM) is a internet station, so I can’t listen to it while I’m on the road.

I solved that problem by recording the stream for a couple of hours using the following script:

#!/bin/sh

# Set the time you want to record
DURATION="45m"

# Start stream dumping
mplayer -cache 150 -dumpstream "http://www.electricfm.com/stream.pls" -dumpfile ~/electricfm.mp3 -quiet&

# Save process id to file
echo $! >~/.mplayer-pid

# Wait X minutes before killing the process
sleep $DURATION && kill `cat ~/.mplayer-pid`

# Remove the file holding the process id
rm ~/.mplayer-pid

I have set cron to run the script every night, and I upload the mp3 every day to my phone.

If I had my phone connected to my pc I could save the stream directly to it, but I also use my phone as an alarm clock, so I have to do it manually everyday before I brush my teeth :p

Post a Comment

Your email is never published or shared. Required fields are marked *