After setting up a recent tracks widget for my homepage with Zend_Service_Audioscrobbler, I came to the disappointing realization many people have lamented. There is no album information in the recent tracks feed, and no easy way to get it through other means. I don't really understand why the album info is not provided in the feed - the album listening stats are available, so it's being stored in the scrobbler database somewhere. I'm sure there's a good reason for this omission, since there have been a number of requests for this feature on the last.fm forums.

Since album detail feeds are available (with track listings!), it's possible to correlate the artist and track names in the recent tracks feed to the albums. It's not an easy task, and it's not 100% accurate, but with a little effort, you can put together a system that can match album info to your recent tracks list, complete with cover art, URLs to the album pages on last.fm, the whole enchilada.

Here's how it works:
  1. Pull your recenttracks feed
  2. Loop through the list of tracks
  3. For each artist, pull the "top albums" list, which for most artists is their complete discography
  4. Loop through the list of albums, and pull the album info feed for each one
  5. Loop through the track list for each album and compare each track name to the name from the recenttracks feed
  6. When you get a hit, the current album info feed has everything you need.
The code to do this is pretty simple - just some nested loops. There is however a big problem we have to deal with. Obviously, this is pulling a ton of data across the wire that we don't need.  It takes a long time to pull all of these feeds, and puts way more traffic on the audioscrobbler servers than they would probably like. It's just not worth the ~30 second load time simply to get album art.

So what to do?