PDA

View Full Version : Using mplayer (or similar) to record mp3 streams


themicah
01-22-2006, 04:27 PM
I'm a fan of several radio shows that are not currently available as podcasts, but that are broadcast online on a regular schedule as streaming mp3s.

I'd like to set up a scheduled task on my VPS that will "record" the streams so I can download them to an mp3 player and listen to them when I go to the gym. I could pretty easily do this on my home computers, but I use laptops that are usually hibernating, and connected via an interference-prone wireless network, so I'd much rather just have my VPS do it.

My understanding is that I should be able to use cron to schedule the task, and use mplayer (or something similar) to grab the stream and dump it to an mp3 file on my server, which I can then download for listening. And not to worry--this will be strictly for personal use like a VCR or a Tivo (I will not be redistributing the captured audio to the wider internet).

The problem is, I know very little about either cron or mplayer.

I found another forum that suggested the following command would do the trick with mplayer:

mplayer -playlist mplayer -playlist [insert stream URL here] -dumpstream -dumpfile output.mp3

But I need to install mplayer first, and I'm not sure how to go about doing that. I can't find mplayer in the default apt repositories, and the main mplayerhq.hu website is down right now. Anybody know where I can grab rpms that will work? Or should I just try to compile it myself? I have the standard rhel4-based rimuhosting distro, if that matters. And will my entry-level Xen VPS be powerful enough to run mplayer? Or is that pushing it? Right now my server isn't particularly stressed (I don't run any databases or any high-traffic websites off of it).

Finally, any other suggestions for how to accomplish this? Are there other stream recording programs for linux that would be better? Is this simply asking too much of a basic VPS?

Thanks!

themicah
01-23-2006, 03:35 AM
http://mplayerhq.hu is now back online. Using their directions I was able to download and install mplayer on my vps, and it works!

I've also read through a quick cron intro and understand how to edit my crontab to schedule mplayer to record.

For example, if I want it to start recording WNYC-FM at 4:59am on Mondays, I create a line in my crontab that says:


59 4 * * 1 themicah mplayer -playlist http://wnychi.streamguys.com/listen.pls -dumpstream -dumpfile /home/themicah/streams/wnyc-monday-5am.mp3


BUT, I still have one problem: how do I make mplayer STOP recording?

If I run the above mplayer command from the command line, I can just hit ^C and it will interrupt the process, effectively stopping the recording.

But what do I put in cron to make it stop the process? Is there a way to use kill? Or does mplayer have something built in? I'd prefer not to kill all mplayer processes, just in case I ever want to have two different streams recording at once that end at different times.

Advice is greatly appreciated!

themicah
01-25-2006, 04:01 AM
After some more research, it appears I could just use "killall -KILL mplayer" as my cron command to stop recording.

But I'm wondering if there's a less thuggish way to go about it, particularly in case I ever have two streams recording at the same time that don't end at the same time.

For example, say I want to record WNYC from 5am to 9am, and KCRW from 8am to 10am.

I could start the two streams at their relative times. But if I use the "killall -KILL mplayer" command to quit the first stream at 9am, it will also kill the second stream when that one still has an hour to go.

Any thoughts on how to get around it?

tomchuk
01-26-2006, 04:18 AM
streamripper is the app you're looking for. It even has a switch (-l) to set the length of recording.