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:
This is a shell script that requires wget (for HTTP streams) or mplayer (for RTSP, MMS, MMST, MPST, SDP streams.) It also uses the pkill command so hopefully you have a pkill that is compatible with the NetBSD/OpenBSD version (which is modeled after the Solaris version.) By default, recordstream puts media files into directories that follow the 'show name' passed to the script in the first argument. It also creates a YYYY.MM directory that links to shows in their own directories if you want to browse by month instead of browsing by show. These directories are created within the directory root 'storage=' as defined in the beginning of the script.
You run it from crontab like this:
# SHELL=/bin/sh PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin HOME=/var/log # #minute hour mday month wday command # # Cartalk - Saturday, 11AM, 1 hour (3600 seconds) 0 11 * * 6 /f/chris/recordstream car.talk 3600 # Alternative Radio - Monday, 8PM, 1 hour 0 20 * * 1 /f/chris/recordstream alternative.radio 3600 # Hearts of Space - Tuesday, 9PM, 1 hour 0 21 * * 2 /f/chris/recordstream hearts.of.space 3600
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:
This script acts as a directory browser with some additional features:
The m3u feature works with various Windows media players, Unix XMMS/gmplayer, and of course it works with the lightweight Unix player interface below.
Obviously, you need to rename this to index.php. To use it, place it in the same directory that you point 'storage=' to in the recordstream script. You also need to point an Apache virtual host there and have PHP working on that virtual host.
I'm sorry that this is written in PHP. But, it is useful that way for one reason. You can chroot apache and everything still works without copying any binaries or libraries into the chroot space. Just dump this script there and everything 'works'. Of course, you would want index.php to be listed as a 'DirectoryIndex' possibility in httpd.conf. When I get really bored, I'll write it in C and you can statically link it to get a similar effect.
The player is just a shell script your web browser can run automatically when you click on a link which returns the MIME type audio/mpegurl. Either version here will allow you to instantly play mp3 or ogg media from your Unix web browser.
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_chrisSee 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 $ s60Note 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.