Yeeee haw, it's the mp3ivo

Here are some very simple scripts that you can use to store and play later your favorite mp3 or ogg streaming shows.

There are three parts to the mp3ivo

first, the recorder:

You can edit variables in the script like the default URL to record from, the directory to dump recordings, and the user agent that wget presents to the streaming server.

If you need more advanced scheduling capability, like, the first Monday of every month, then you need to either use something other than cron (maybe at?) or write a wrapper that checks which Monday it is when your cron runs the recordstream script on every Monday.

Finding the correct URL to record from may be a challenge. You will have to download a playlist file and parse it for the actual URL of the streaming server, which may be hidden by a series of HTTP redirects.

next, the streamer:

and last, the player: Mplayer uses the mpg123 code for playing an mp3 stream. None the less, the mplayer version is superior for at least two reasons. First, mplayer allows you to seek through an HTTP stream (it will reconnect to the HTTP server if it has to). Second, mpg123 has serious bugs reading live mp3 streams, as it is not very smart about finding the correct mp3 header. Some times, mpg123 will come up with bogus mp3 bit rate data, resulting in loud noise or other sorts of dissatisfaction when you can't play the media file. Mplayer has a better method of finding the correct mp3 header, and as such doesn't exhibit these problems. In addition, mplayer can play Real and other proprietary codecs (if you have the Windows Real libraries installed, and if you are on i386.)

The mpg123/ogg123 version is nice for one reason, mpg123 and ogg123 are a lot smaller than mplayer.

The mplayer version creates a FIFO in /tmp/.mp3streamerfifo_USER, so when I'm logged in as chris, it is /tmp/.mp3streamerfifo_chris and I can use the FIFO like this to move around:

$ echo "seek 10" >/tmp/.mp3streamerfifo_chris 
$ echo "seek 60" >/tmp/.mp3streamerfifo_chris
$ echo "quit" >/tmp/.mp3streamerfifo_chris  
See the mplayer manual page for a complete list of FIFO commands. You could easily store aliases in your .profile so that you could seek with a simple command, like:
alias s10="echo \"seek 10\" >/tmp/.mp3streamerfifo_chris"
alias s60="echo \"seek 60\" >/tmp/.mp3streamerfifo_chris"
alias b60="echo \"seek -60\" >/tmp/.mp3streamerfifo_chris"
alias p="echo pause >/tmp/.mp3streamerfifo_chris"
alias q="echo quit >/tmp/.mp3streamerfifo_chris"
Then you can just seek through commercials by hitting the up arrow and return in a shell window:
$ s60
$ s60
$ s60
Note that pause doesn't actually work very well because Apache will abort an idle connection pretty quickly. Also, every media player out there interprets the timeout of an HTTP session (and subsequent disconnection by the server) as the end of the media. You can solve this by manipulating the TimeOut directive. Perhaps a 'TimeOut 7200' in the streamer virtual host container might give you ample time to go out to lunch, stop at the DMV, and come back home to your favorite keltic music show.