Step 1: Get Ubuntu, create directories
If you already run Ubuntu, the only things you need are freely available through apt. Use the following commands at a terminal to install Lame, Mplayer and KCron.
sudo apt-get install lame mplayer kcron
Type in your password and confirm the installs.
Use the following commands to create the folders you'll need.
sudo mkdir /scripts
And this command to take ownership of the directory you just created:
sudo chown YourUserName /scripts
Step 2: Create Streamrecord Script
1. Open mplayer, point to audio stream on Internet
2. Record stream to wav file in /tmp directory
3. Kill mplayer process when show ends
4. Convert /tmp/mystream.wav to mp3 file, name it with today's date and move it to more 'user-friendly' directory under user folder.
5. Delete wav file in /tmp directory.
To achieve this, you'll first need to find out the URL of the stream you're accessing. For an example, I'll use the CSPAN radio stream, and record it between the hours of noon and 2pm Monday thru Friday. Here's the text of the script:
mplayer "mms://rx-wes-sea20.rbn.com/farm/pull/tx-rbn-sea34:1259/wmtencoder/cspan/cspan/wmlive/cspan4db.asf" -ao pcm:file=/tmp/mystream.wav -vc dummy -vo null ;
lame -m s /tmp/mystream.wav -o "/home/shawn/Music/CSPAN/My Show - $NOW.mp3" ;
rm /tmp/mystream.wav ;
Copy this text to a blank file using Gedit or Vi, and save it as "streamrecord". You'll need to edit the areas of the script in italics, as these wont apply to you. The text after mplayer is the URL to the stream you want to record, this will need to be replaced with your stream's URL, which can be found easily by going to the stream in Firefox, letting the mplayer plugin start, then right-click and choose "Copy URL".
Step 3: Save script, make pkill script and make scripts executable
chmod 700 streamrecord (This makes the script you just created into an executable file.)
Create one more file in the /scripts directory. This will be called pkill, and will be your hitman. That is, it will kill the mplayer process to allow the first script to continue with renaming and encoding the captured stream. The full text of the pkill script is exactly as follows:
Now, this breaks scripting etiquette, by not having #!/bin/sh at the top, but it works for me. Once you've saved the file pkill in the /scripts directory, use the chmod command again to make this one executable. You need to be in a terminal session, in the /scripts directory first, then type:
chmod 700 pkill
A quick "ls" will show you the files you just created, now in a lovely green instead of the standard black.
Step 4: Use KCron to schedule your jobs
The second script you made, called 'pkill' is what actually ends mplayer and allows the first script to continue. You'll need to set up another cron job to run that script as well. For my example, I end up with two jobs in KCron. (see 2nd image)
Step 5: You're in Business!
P.S. I know my methods are a bit crude, as there are probably best-practices that I'm not following in some of my steps, so please don't school me on Linux 101, this is just a quick and dirty way to never miss your favorite audio stream.