The stream I want to record is already in the format I want

This simplifies things a bit. If the stream you want to record is already in the format you want to use, you can use the -dumpstream flag instead. Your streamrecorder script will look like this instead:

 [bash]
#!/bin/sh
mplayer -playlist /home/username/scripts/playlist.txt -dumpstream -dumpfile /home/username/FlockofSeagulls_`date +%b%d` -vc dummy -vo null ;

This will result in a file called FlockofSeagulls_May20, without a file extension, in username’s home directory. This eliminates the intermediate temporary file and the encoding step. You can add the extension after `date +%b%d` just like in the previous script if you want. It doesn’t matter as MPlayer doesn’t require the extensions in order to play the file but your desktop environment may like the extensions in order to associate the file with whichever media player you’d prefer when you click it in your file browser.

What’s the deal with the playlist flag?

If you’ve been to this site before, you may notice the -playlist switch that was talked about in the MPlayer playlist, and Cron-MP3 Alarm Clock articles. In order to understand why you need the playlist switch when playing streaming audio, you need to understand a bit more about how streaming audio works.

Each streaming format has a kind of playlist file that your music player uses to redirect it to the actual music stream. For Windows Media it’s .asf, for Real Audio it’s .ram, MP3 uses .m3u and .pls. Even though each format has it’s own unique file extension, each file is basically the same. They’re just text files with urls pointing to the actual streams. Take your editor and open the playlist.txt file and see for yourself. If you see one of those file extensions, you’ll need to download the playlist and use the -playlist switch to play/record those streams.

Ogg, however, is an exception. Most Ogg streams, such as those from Icecast servers, don’t require the -playlist switch because the server handles all of the redirection without the need for a playlist. Those Ogg streams that do require the switch are usually just a static directory full of oggs. In such an event, the static directory versions usually implement a playlist file and use the same file extensions as MP3.

In theory, the -playlist switch doesn’t require the playlist file to reside on your hard drive. You should be able to just type mplayer -playlist http://full/url/to/playlist.pls and it should work. However, I’ve had mixed results with that method. Downloading the playlist to hard drive has worked for me every time. Feel free to experiment using the URL instead of the downloaded file, as your results may differ from mine.

Text by Philip McClure