I’ve already described how machine tags on Huffduffer trigger a number of third-party API calls. Tagging something with music:artist=...
, book:author=...
, film:title=...
or any number of similar machine tags will fire off calls to places like Amazon, The New York Times, or Last.fm.
For a while now, I’ve wanted to include Flickr in that list of third-party services but I couldn’t think of an easy way of associating audio files with photos. Then I realised that a mechanism already exists, and it’s another machine tag. Anything on Flickr that’s been tagged with lastfm:event=...
will probably be a picture of a musical artist.
So if anything is tagged on Huffduffer with music:artist=...
, all I need to do is fire off a call to Last.fm to get a list of that artist’s events using the method artist.getEvents
. Once I have the event IDs I can search Flickr for photos that have been machine tagged with those IDs.
There’s just one problem. Last.fm’s API only returns future events for an artist. There’s no method for past events.
Undeterred, I found a RESTful interface that provides the past events of an artist on Last.fm. The format returned isn’t JSON or XML. It’s HTML. It turns out that past events are freely available in the profile for any artist on Last.fm with the identifier last.fm/music/{artist}/+events/{year}
. Here, for example, are Salter Cane gigs in 2009: last.fm/music/Salter+Cane/+events/2009
.
If only those events were structured in hCalendar! As it is, I have to run through all the links in the document to find the href
s beginning with the string http://www.last.fm/event/
and then extract the event ID that immediately follows that string.
Once I’ve extracted the event IDs for an artist, I can fire off a search on Flickr using the flickr.photos.search
method with a machine_tags
parameter (as well as passing the artist name in the text
parameter just to be sure).
Here’s an example result in the sidebar on Huffduffer: huffduffer.com/tags/music:artist=Bat+for+Lashes
It’s messy but it works. I guess that’s the dictionary definition of a hack.