Making A Radio Station With Ruby
Posted by Eric Mill
Feb 12
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.
Comments on this post
Feb 14
Kevin Marsh said,
Very nice! My only beef was that your call to Dir#entries does not recurse subdirectories, so I replaced it with a call to Dir#glob. This also has the benefit of reducing the regex. The major change is on rubedo.rb:273 to
Dir.glob("#{Rubedo::MUSIC_FOLDER}**/*.mp3").each do |filename|but I can provide a diff if you’d like.Feb 14
Eric Mill said,
Excellent! It was a feature I was planning on soon, so I’d definitely be interested in seeing a diff, and I can likely incorporate your code posthaste. Did you have to edit dj.rb as well? The way the code is, I’m pleasantly surprised to hear that a relative path can float through the code as effortlessly as a filename.
Feb 23
Kevin Marsh said,
Do you have a preferred email address?
Also, do you have any plans to add any new features? On my list would be picking up/showing more ID3 metadata info, and doing the sorting client-side in JS.
I need to investigate transcoding down to 128kbps as I use this remotely from my home to office. Occasionally there are buffering stalls as some of my music is in 320kbps, which exceeds my upstream. Even a separate 56kbps stream for the Treo on the go would be swell too.
Feb 26
Eric Mill said,
You can email my thoughtbot address, emill@thoughtbot.com.
Yeah, I am adding new features. I just released 1.1, which included a Campfire client, and bundled a couple dependences (Sqlite and Markaby). I’m planning on making the Campfire client more of a daemon, so that it can accept commands as well as post the song.
I’m making an embeddable flash player so that you can listen to the radio from your browser, Pandora style. It’d just be a small play/pause button, nothing elaborate. It turns out this is way easier than I would have thought possible, and I’ve already got a prototype working.
So yeah, it’s still in active development. I’m still really dissatisfied with this being an “Icecast Source Client”, and only being runnable on Linux, though. My coworker Tammer is working on “Rubycast”, a lightweight Ruby icecast server, to solve the problem though. We’ll see how it goes.
Mar 08
Eric Mill said,
I’ve committed this to SVN.
Mar 08
Eric Mill said,
Umm, by “this” I mean, recursive directory support. It was just as easy as you say, Kevin!
Sorry, comments are closed for this article.
© 2000 - 2009 by thoughtbot, inc.
written by a bushel of tiny robots
Come “ride the toad” on Hoptoad, the app error app.
Thunder Thimble: Brand monitoring for social media.
Widgetfinger: Simple content management for simple websites.
Tee-Bot, funny shirts your friends won't understand!
Umbrella Today: “It’s like totally the simplest weather report ever, Julie.”
Thoughtbot
thoughtbot is a technology consulting firm that provides web application development and design services. We focus on building modern systems, embracing good ideas and delivering elegant solutions.
Interested in learning Rails?
Sign up for our beginning or advanced training.
Archives