August 16, 2005

Tunes on Rails

I've finally brought back the "Current Tunes" section of the blog. The sidebar now displays whatever song I'm currently listening to in iTunes and a list of the last 50 songs I've played is here. The song links take you to the iTunes Music Store.

All of this brought to you server side by Ruby on Rails. I hardly do any web programming, but Ruby on Rails has had quite the buzz about it, so I've been wanting to try it out for a while now. I've also been wanting to bring back the Recent Tunes section of the site, and RoR seemed like a perfect fit for that.

Justin William's tutorial on MacZealots got me up and running with Rails on my Powerbook and the OnLamp tutorial got me 90% of the information I needed to get the app working. I feel like I should go into more detail about the development process, but there's really not much to say. After doing the OnLamp tutorial, getting my app working was extremely straightforward. I guess this is why people love Rails.

So getting the app running on my local machine was a breeze, but getting it running on my server was another story, since 1and1 does not support Ruby on Rails out of the box. Fortunately, I did find this script which helped me get most of what I needed installed in my home directory on the server. Then I had quite a time getting a symlink from my web directory to the app's public directory setup and working. Since the symlink was not at the root of my web directory, I had to modify the .htaccess file to properly point to the dispatch.cgi file. Unfortunately, the first time I did this I apparently deleted a crucial space between the $ ending a regex and the path to the dispatch.cgi file. It took me a good while before I figured out that's why things weren't working.

The other issue at the moment is loading the Recent Tunes page is quite slow since I haven't set up FastCGI, and I'm not sure that I can with my current hosting plan. I'll likely be switching hosts in the near future, so I'm not too concerned about that right now.

I guess the last bit of info on this topic is the client side part of the app. It's just a small Cocoa app that registers for the com.apple.iTunes.playerInfo distributed notification (which I found thanks to Notification Watcher). I also make use of the spiffy CURLHandle framework.

Interestingly, I just noticed that the notification does not include Rating and Play Count information for all songs. I'll have to figure out why that is. Other than that though things seem to be working after having the client running for about an hour on my laptop. And I just fixed the bug that caused a song to be listed multiple times if I pause and then played ([album isEqualToString:m_currentSongArtist]? that'd be a typo, though it would be true for self titled albums). The true test will be running the client all day at work tomorrow.

At some point I'll probably clean up the code a bit and package both the client and server and put it up for download, but no promises on when that might happen.

Posted by Jason at August 16, 2005 12:50 AM