Hak5
Save 10% at GoDaddy.com with coupon code HAK

Analog5:000 Article 004

From Hak5

Jump to: navigation, search

Hak.5 Radio - How does he do it?!

By: mubix
Published: January 20th, 2007


#!/bin/bash

####################################################################

create analog_stream;

execute(article["Hak.5 Radio - How does he do it?!"]

By mubix 2007-01-12

####################################################################


Well, I am finally putting it out there, the down and dirty of how Hak.5 Radio comes to life. In the following paragraphs I will tell you how I get the Song Request site up as well as the back end server portion. Check it out.

I'm going to start with the server build, because without that, you are just talking into a microphone that goes nowhere. Okay, so we need a server. A Linux one will do, whether it is hosted by a provider, such as Hak.5 Radio's is, or you can host it at home. Either way, a stable, always on, Linux machine is needed.

Cool. We have a server and it’s running Linux. Next we get to pick a streaming service daemon. Now, the two widely used are Shoutcast and Icecast. Both are great service daemons and have so many configuration settings that they are flexible from 5 listeners to 5000 with zero growing pains. But, what is going to make me choose one after the other you say? Well, you can google a blow for blow comparison, but this is how I see it:
Shoutcast has a listening service that you automatically get posted on which will bring in quite a few listeners of “off the street” if you will. Icecast on the other hand, has smaller delay on your stream. This is important when taking calls on live shows. Icecast has a 3-8 second delay from the time it hits the microphone to the time the listener hears it. Compared to Shoutcast’s 30-40 second delay, it makes for a tough decision for any new radio station.

Server, check! Service daemon, check! Wait…. You mean I have to configure it? Yup, the cruel truth of Linux is you have to configure everything. For both Shoutcast and Icecast, the manuals, FAQs and Forums are undeniably better than anything that will ever fit into an article for any eZine/magazine. Thus, I will leave the configuration up to you. I will go over a couple things to look into in the configuration during other sections of this article.

Now that it is configured, we want to make sure that it stays up. There are a couple of ways to do this. The easiest is to make a cron job (scheduled task) to check if the server is running and to run it if it is found not to be running. The following script does just that.

	#!/bin/bash

	if [ ! "$(ps ax | grep icecast | grep -v grep)" ]
	then
	  screen -d -m icecast -c ~/icecast/icecast.xml
	fi

Save the file as "checkice.sh" and run chmod +755 to make the file executable. Run crontab -e and put */15 * * * * /path/to/file/checkice.sh >/dev/null in or, mv the file into one of your distro's /etc/cron.(hourly/daily/weekly) folders. Either way you will be making sure that your server stays afloat. Now, you might notice that I used the command 'screen'. Screen is a way of running things on a virtual console. Basically it's a "insta-daemon" program. I will have links to everything I go over at the bottom of this article.

Ok, we are all done on the server side. But what does all that hard work do? Absolutely nothing without a client or 'streaming software package' to send the music or video to the server for people to get it. There are a limited number of programs that can do this. SAM Broadcaster is the most widely used, but costs money.NSVTools w/ NSVCapture is used for video, and I'll go into that a bit later, but it is free. WinAMP w/ Oddcast is also a free alternative. I actually use all 3 of these solutions to run Hak.5 Radio.

I use SAM Broadcaster when ever I want to "go live", where I will be DJing myself, queueing up songs and using the mic. WinAMP with Oddcast can do this just fine, and is a awesome alternative, SAM just has a better interface and more options. I use WinAMP w/ Oddcast and another plug-in for WinAMP called "Song Requester". Guess what it does? Yup! Gold star for you. It auto-magically generates a website of all the songs in your play list and allows Internet users to request songs by searching for a song and clicking on it. You can also limit how many songs a single user (by IP) can request at one time. The default is 3, but on a low traffic station, I have found that 5-10 works better.

The last trick to the radio station is the ability for listeners to upload songs that they want to hear. For that I use a configured HFS server on the "AutoDJ" box that has a virtual folder that allows the upload of mp3s, waves and other such audio/video formatted files. WANQer is yet another plug-in that watches that folder for new songs in the folder and adds them to the play list. The only problem is Song Requester doesn't update it's cache auto-magically. I had to set up a scheduled task to push the update cache button for every 5 minutes to get around this obstacle.

Other than that, that is the basics of how Hak.5 Radio works. There are a lot of little tweaks and specific configurations that will be unique to how you set up your radio station but this article should be a huge bump in the right direction. If you have any questions you can find all kinds of ways to get a hold of me on the Hak.5 Forums, in the Hak.5 IRC, skype, IM, http://www.mubix.com/, http://mubix.vox.com/, and yes, even on MySpace.

mubix
Jd.mubix@gmail.com
http://www.mubix.com/

Links:

Shoutcast
Icecast
Intro to Cron
Screen@ Wikipedia
SAM Broadcaster
WinAMP
Oddcast
NSVTools
SongRequester
HFS
WANQer

Analog5 Front Page