Making A Radio Station With Ruby

Making A Radio Station With Ruby

As far as I know, everyone at thoughtbot likes everyone else. I can tell because everyone mocks everyone else mercilessly. Figuring that there’s no more effective way to mock people than over their musical tastes, I thought an office radio station would be a great little service to have running. I just wanted a way for all of us to play our music and have everyone listening to the same thing at the same time. We should be able to pick a folder on the network drive, dump our MP3s there, and then go someplace in our browser and DJ up some jamz.

About a month ago, I went looking through all kinds of solutions, but they were all too difficult to use, or showed dealbreaking bandwidth issues, even over our LAN. The Icecast music server looked to be the best solution, but the server only takes care of the network part, allowing a large number of people to connect to a single stream. Icecast still requires another program, a source client, to constantly feed it a stream of music to broadcast. I searched, and couldn’t find any source client which met my use case of let anyone queue anything in a common directory at anytime, over the web. This was really surprising, because how else would you want to run a radio station in your office? At a minimum, I was going to have to write my own web interface, so I decided to write my own source client too.

Today, I’m releasing that source client, which I have titled Rubedo. Rubedo is a nice, pretentious name, Latin for reddening, that comes from alchemy, and is often used in Jungian psychology. More importantly, it sounds pretty close to Ruby and Radio all mashed together. It has an official home here at thoughtbot, and a community home at Rubyforge.

Really, Rubedo is a very simple app - the basic functionality I described above was finished after a day of work. Since then, I’ve devoted some of my time at home and work to make Rubedo look good, work easily, and run reliably. I used Camping for the frontend, and ruby-shout to communicate with Icecast. Camping is exceptionally easy and enjoyable to use, as I’ve raved before, and was perfect for my needs. The Camping frontend and the source client are separate processes that share an SQLite database. Though it’s two processes, you only need to run one file.

Here’s a look at what we have running here at thoughtbot (click to see the big version):

The lefthand column shows all the songs available, and the righthand column shows the queue and what’s Now Playing. Since we made it publicly accessible for a couple offsite employees, I removed the URL from the image. Also, your title doesn’t have to be Thoughtbot Radio, obviously, it’s a setting in the (YAML) config file.

A closeup of the radio portion of the UI:

Currently, the big barrier here for Rubedo is the dependencies. There’s no install process for Rubedo itself (just unzip it), but you will have to install Icecast, libshout, SQLite3, and a few gems. Icecast has a few dependencies of its own, including libogg and libvorbis. I’d recommend using a package manager, though tarballs are available and Rubedo’s readme provides links to them. These are difficult to compile on Windows, so Rubedo officially only works on *nix-based systems. One of the next steps for Rubedo is to actually replace Icecast and libshout with a pure-Ruby lightweight server. I’d be very interested to know how well Ruby could handle something like this, so I’ll be sure to let you know. In the shorter term, I’ll make an install.rb that will download and the install dependencies for you. In the meantime, give it a go.

In addition, I’m making a simple Campfire client for Rubedo which can make announcements to your Campfire room, or accept commands. I’d like Campfire interactivity to be a big part of Rubedo. I also have a dream of making an interface to your radio station easily embeddable, just by adding a JavaScript snippet to your page. While I consider Rubedo as it is a complete, usable piece of software, there’s still lots more work to do to make creating a radio station for your group dirt easy.

Eric Mill Developer

Sharpen your programing skills by completing coding exercises that are reviewed by other developers at Upcase today.