Internet Radio in NetBSD and Linux without KDE or GNOME
[ Sunday, 16 September 2007, P2O2 ]
Listening to Internet Radios seems easy nowadays with the rampant powerful graphical environments of KDE and GNOME. One or two clicks and, bingo! We hear our favorite music or a Radio Talk Show. Multimedia applications like Kaffeine, Amarok, Rhythmbox, StreamTuner, GMPlayer, Totem, Xine, Xmms, to name a few, have dominated the GNU/Linux and BSD worlds for good.
Given that the computer you have is well equipped with processing power, i.e. has got enough memory and a mighty processor, it will do well with all those graphics overkill. But a lot of users own older machines with 400 MHz Celerons and 128 MB DRAMs which are hardly able to run the graphical behemoths. Should they get rid of the pleasure of listening to the Internet radios? Never!
I’m going to show you what to do to have the Internet streams heard on your computer without swallowing up your precious resources. You will make use of the famous Mplayer console player, OGG encoder, Aumix mixer, excellent Xdialog widgets, and less known Shstream stream grabber. A few simple scripts to glue the whole shebang together you could write on our own, but I did the dirty work for you.
Digging Up the Stream Address
A lot of Internet radios can be played from within web browsers thanks to prevalent audio plug-ins. They offer the simplest way to get the Internet Radio heard on your computer. Some professional services provide even their own additional windows to play audio and video data, e.g. Foxnews and BBC World News. But they make use of the technology used by the most popular audio players. Accessing the radio streams through those jumbo-sized web browsers isn’t the solution for us. What we need is the stream addresses only. And that’s where the snags come to light.
But digging the hyperlinks out of html noise isn’t trivial. Most often thanks to the “new” M$ “technologies”, which hide hyperlinks of the radio streams from prying eyes of curious users. To put it short, first you have to find a radio station button on an HTML page. They are in forms of Microsoft Media Player or RealPlayer icons. Click one. If you got no right plugin you’ll end up with popped up window asking you what to do with the address/file. Save it to your disk as it is not a stream but a file with a valid stream address. Alas, too many times that’s not the end of your problems. The stream hyperlinks are often hidden within the second or third HTML file! All you have to do in such cases is further download consecutive files until you’ll be able to dig up the correct address.
Screenshots for the chapter: inetradio_diggingup.html.
MPlayer Is The Best!
I won’t exaggerate when I say that this application alone with appropriate codecs is irreplaceable in Linux and BSD systems! All distributions nowadays are ready to run it. Some are distributed with Mplayer files and corresponding proprietary codecs, others put the “forbidden” codec libraries in separate repositories, but they are easy to download and install.
Starting Radio in the Terminal
I must admit here that I prefer console/terminal applications whenever possible. I have a 400 MHz Celeron machine too. This approach keeps the system ready to take more resource hungry tasks without adverse effect to present tasks.
You can tune in to the Internet radio stations in many ways. Let’s start from the simplest. All we have to do is to open a terminal window and type in “mplayer” command followed by a stream hyperlink. If you do not like to type the same strings every time when you want to listen to your radio, you can hide the appropriate command inside a script, or make an alias in your login configuration file. Let’s look at the example file named np_radio_israel:

Picture 1: More “sophisticated” script playing Internet radio
in its own terminal.
#!/bin/sh
# Description: Radio Israel
#
mplayer -cache 128 mms://s96wm.castup.net/992230002-52.wmv
For better flexibility such a script might contain a command to make mplayer to run in external terminal. It would allow user to set terminal attributes like its geometry, background and foreground colors and fonts. Pay attention to the ending part: -e np_radio_israel. The “-e” option tells terminal to start application, here np_radio_israel from above example.
#!/bin/sh
# Description: Radio Israel played in xterm terminal
#rxvt -title "Radio Israel" -geometry 50x15+0+0 \
-fn -misc-fixed-medium-r-normal-*-12-*-*-*-*-*-iso8859-2 \
-cr yellow -fg blue -bg white -e np_radio_israel
xterm -title "Radio Israel" -geometry 50x15+0+0 \
-fn -misc-fixed-medium-r-normal-*-12-*-*-*-*-*-iso8859-2 \
-cr yellow -bg blue -fg white -e np_radio_israel
Probably your system was installed with a lightweight Window Manager like TWM, IceWM, Fluxbox, etc. I strongly recommend to put your script into the Manager’s menu. Now any Internet Radio would be at hand and you won’t bother opening a terminal to type in your radio script’s name.

Picture 2: ListBox in full view.
Screenshots and scripts for the chapter: inetradio_terminals.html.
Selecting Radio Stations in an Xdialog Window
We’ll make use of Xdialog now, to make access to your Internet Radios even easier. Xdialog is a rich set of GTK 1.2 widgets. Every widget is associated with a small code module, which can be inserted to any shell script written for BSD or GNU/Linux systems. We will use two widgets – a ListBox and a MessageBox.
When you select a radio station the new windows will show on your screen. This time it will be a MessageBox widget.
But that’s not all. Select Aumix button and a third window will be displayed. It will be a terminal window trimmed to “aumix” command. Of course the Radio Window will restart again but this time with only one button. Pressing [Turn Off] will switch off the radio, that is it will “kill” MPlayer. Aumix will stay for further usage. It can be closed manually.

Picture 3: Xdialog widget with Israel Radio playing in background.
More screenshots and scripts for the chapter: inetradio_xdialog.html.
Recording Streams with MPlayer and ShStream
“shstream” is a bash/sh script which creates MP3 or OGG audio files from tuned in audio streams. It uses MPlayer to capture streams and an ogg encoder to change the raw stream data to ogg files. The “shstream” uses individual config files for recordings. You can put them in the ~/.lnbsd directory (choose your own directory, but make appropriate changes to other files). I suggest to name the config files with unique and readable names, e.g. np_stream_wind_savage.conf. Where WIND is a radio station code (WIND from Chicago), with Savage being a name of a radio talk show host. There’s no limit in the number of config files.
Names of variables in configuration files are self explanatory. For example I decided to record one file at a time and close to 1/2 hour long (1800 s – 20 s = 1780 s). I didn’t set the time to full 1/2 hour (30 min = 1800 s) because recordings are stopped through “kill” command which stops (kills) all MPlayer processes. Another thing which needs to be set is the bitrate. It depends on the operating system. Just check it on your own. Author’s OGG encoder works well with a bitrate of 64 kbps. Of course, don’t forget to enter the radio station address (streamurl) and target directory (destdir) for ogg files.
numoffiles="1"
filelengthinsecs="1780"
onefile="0"
# for MP3
#bitrate="32"
# for OGG
bitrate="64"
format="ogg"
ext=".${format}"
filename="savage-`date +\%Y-\%m-\%d--\%H-\%M`"
destdir="${HOME}/data/streams"
pipedir=" \
${destdir}/savagestreamfiles-`date +\%Y-\%m-\%d--\%H-\%M`"
streamurl="http://gicst.streamos.com/wind_22"
partialratio=".85"
user="lnbsd"
group="users"
#permissions="644"
#startcommand="sh /etc/rc0.d/K10mldonkey"
#endcommand="sh /etc/rcS.d/S97mldonkey"
#networkresets="3"
#resetcommand="sh /etc/init.d/networking restart"
Stream capturing, grabbing, or dumping, as the technology is sometimes named, can be done without use of Shstream. Mplayer can do the same with “dump” option. But the Shstream script is a whole lot more flexible. Running Mplayer alone only adds you new tasks, e.g. format conversion. And you still will need to set up other programs, like cron for example.
mplayer http://217.71.208.37:8006 -dumpstream -dumpfile stream.asf
More on Mplayer’s dump option: 3.4.1. Saving streamed content.
Screenshots and scripts for the chapter: inetradio_recording.html.
Use Cron And Sleep Well
No one at their sound senses will wait until recording time has come. ShStream should be started with help of system’s “cron”. An example below explains how to make the cron to do work for us. The 17-19 hour (17:00 AM, 5 PM) entry (3 hours) are in CDT (US Central Time, Houston, TX) as I have computer time set to CDT. Mr. Savage can be heard 24:00- 3:00 Warsaw time (Central European Time), during sleep hours in this part of the world. Two numbers at the beginning, “0,30″ tell cron to start program at full hour and after 30 minutes. In other words, cron is set to make 6 stream chunks, each 30 min long. Compare with shstream config file, whose listing is shown above in the article.
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/temp/crontab.890 installed on Thu Feb 15 09:03:18 2007)
# (Cron version -- $NetBSD: crontab.c,v 1.26
# 2005/03/16 02:53:55 xtraeme Exp $)
#
# Mr Michael Savage Radio Talk Show
0,30 17-19 * * 1-5 /home/lnbsd/bin/np_stream_wind_savage
This very short article is a compilation from an article which comprise of 5 parts concerning Internet Radio. The original html pages contain a lot of screenshots what will certainly help to understand the text. You’ll find all necessary links there as well.
This article in a long extract from the original one published on author’s website. Read the full article here: inetradio.html.
Proof-read by trashcat
Subscribe to RSS feed for this article!
4 Comments
- A hyperlink: <a href="polishlinux.org">GNU/Linux for everyone!</a>,
- Strong text: <strong>Strong text</strong>,
- Italic text: <em>italic text</em>,
- Strike: <strike>
strike</strike>, - Code: <code>
printf("hello world");</code>, - Block quote: <blockquote>Block quote</blockquote>

As much of a console/terminal buff as I am (and a good other amount of Linux buffs) I use GUI-based apps most of the time, depending on the situation, and use a desktop environment ALL the time, unless I’m edited my xorg drivers or something.
Now, with that established, would I use internet radio? I don’t know, but this is handy for those in less populated areas using Linux, as the more of a “cultural” or “urban” center you’re in the easier it is to obtain news and such.
Also done with the obvious, I may very well bookmark this one. Thanks.
Why don’t you install mpd and control it with ncmpd???
Tom, I like Mr Savage but he lives and works in USA.
There’s only Internet left to have Him spreading the Truth within the walls of my room.I’m not for the news as such, more for the US Radio Talk Shows.
Carlito, let me ask frankly – what for? For recording or for listening? Wouldn’t the mpd be an overkill for the tasks I described above?
Regards,
P2O2
Thanks for a great article! I to use very limited hardware for audio playback. I have a server in my boat built around a VIA mini-itx card. I use mpd for streaming. I control it with mpc/ncmpc from the command line or with Pitchfork as a web GUI. Works great!