Last.fm Recent Tracks RSS Consumption

iTunes + Last.fmThe Harold B. Lee Library recently started streaming music to one section of the library.One of the questions we’ve gotten since providing this service is, “Where can I see a list what is playing?”. I figured it was somehow possible and a friend helped me figure out how.

We use iTunes to stream the music to the ‘Music Area’ (clever name) of the library. Last.fm, through their ‘Scrobbling’ software, provides access to an RSS feed of your latest tracks. Here’s my recent tracks feed. (Insert your last.fm user name in the url to get your own feed.) Once I installed the Last.fm application on the remote computer, our feed started working instantly. That was step 1.

Step 2 was to get that feed published on a library page for easy advertising. Thankfully, jQuery has a plugin called jFeed. It does what you think – parses the RSS XML so you can output it as HTML – tada! That was relatively easy – they even provide a method to overcome cross-domain scripting woes. Step 2, Check!

Wait! The timestamps are 6 hours off! What?! I don’t know why this happens but I’m not the only one. But I assume that the 6 hour difference is consistent and create a fix thusly:

var timestr = Date.parse(item.updated);
var newtimestr = timestr - 21600; //subtracting 6 hours (in seconds)
var timeago = jQuery.timeago(new Date (newtimestr)); //this is explained in the next paragraph

Everything is now working fine and I could have left well enough alone, but I didn’t. The feed was displaying, the links back to last.fm were working, everything was special. However, I didn’t like the format of the datestamping: Tue, 19 May 2009 22:50:43 +0000. This is the standard date format for RSS publishing. And it is a great format – for computers. However, I wanted to display it in a human friendly way.

Enter timeago. Timeago is a jQuery plugin that does magic – it takes the loverly, aforementioned GMT timestamp and turns it into this: 7 minutes ago. That’s a lot more human friendly. And since I have more humans than computers as friends, I went with that option.

Obviously, this would have been easier for some to do in PHP. And it probably would have made more sense. Maybe someday I’ll do that.


2 Responses to “Last.fm Recent Tracks RSS Consumption”

  1. Awesome work, Tom.

    The only problem you’re going to run into is when you change between Daylight Saving time and Standard time. You’ll want to investigate the php option deeper because it has built in functions to accommodate that change.

  2. Interesting. Does GMT not adjust for daylight savings? I wonder if there is a way I could test for that right now…


Leave a Reply