Not infrequently while I’m listening to music the thought will occur to me that the song I’m listening to is so awesome that I really should share it with everyone. Yes, but how? Last.fm recently added a feature to let you embed a mini-player to any of the songs they stream (some as full tracks, some as 30 second clips), but getting the code and pasting it into a new blog post sounds like way too much effort. Sharing great music is fine and all, but let’s be reasonable here. This sounds like a job for a script, and once again I’m impressed by just how easy it is to get stuff done with Ruby. Taking advantage of the XMLRPC libraries I posted about earlier, I was able to write a script to get the current track info from Winamp, grab the resource id from the Last.fm page for the track for embedding it as a player and post it to a weblog. The only thing it requires that’s not in the standard library is the Hpricot gem for parsing HTML to get the resource id from Last.fm. It’s only about 80 lines of code. Every time I do something with Ruby, it ends up taking much less effort than I would have guessed. Granted this doesn’t have a lot in the way of error handling currently, and it only works on Windows and with Winamp at the moment, but it’s functional enough for me. Maybe I’ll add more to it later though. I’d like to turn it into an actual Winamp plugin but the thought of writing it over in C++ just gives me the jibblies, since it was so dang easy in Ruby. At any rate here’s the script in its current unpolished bare-bones form, just in case anyone finds it useful: SongPost 0.1
Comment by Tobin on 2007-05-27 11:09:03 +0000
Very nice, very nice.