What's that you're listening to?

I’ve been doing a little tinkering behind the scenes here.

On my journal page, under the heading “music”, I have a “last iTunes track” feature. This shows whatever song I’m listening to. There’s a link through to the iTunes music store for the track. There’s also a link to Google for a search on the artist.

I’ve modified it so that it now offers a third link, this one to Amazon. Wherever possible, there’s also album artwork displayed. This is done using a combination of iChatStatus, PHP, Amazon’s web services and XSLT.

iChatStatus is a nifty little app that basically runs an applescript whenever the current track in iTunes changes. A number of scripts are available. The default one updates the availabilty status in iChat to show the name of the current song and artist. An extension of that script also changes the buddy icon in iChat to show the album artwork of the current song. Another script FTPs a text file containing information on the current song to a specified server.

What I’ve done is to combine those applescripts into one. When a track changes on iTunes, my iChat status is updated, my iChat buddy icon changes and a small file is uploaded to adactio.com. This file is then included via PHP on my journal page.

To get the Amazon functionality to work, I only needed to change the applescript slightly. Basically all I do is, as well as writing out some HTML, write out a PHP variable. Here’s the text file. You can view source to see the PHP variable being set (.txt files don’t get parsed when they’re viewed alone like this but they are parsed when they’re included via a PHP script).

Now I have a PHP variable containing the album and artist names. From here, it’s a simple matter of adapting the scripts I used for The Session Shop.

I make a call to Amazon’s web service running a search on the album and artist. I’m not interested in seeing all the results: I just want to show the first one. Using a very simple XSL file, I get the ASIN number of the album and, where available, the album artwork.

Using PHP’s readfile function, I dump the generated XHTML to the screen. If, for whatever reason, something goes awry with Amazon’s web services, a simple link to search Amazon for the album and artist appears instead.

That’s it. If you’re visiting my journal page and see that I’m listening to an album that you’d like to check out, one click will take you straight to Amazon with an option to add the album to your shopping cart, buy it and enrich this associate by a couple of cents.

Next step: adding the means to toggle between amazon.com, amazon.co.uk and amazon.de. Watch this space…

P.S. Please forgive the preposition-ending title of this post. But what am I supposed to say? “What’s that to which you’re listening?”… it just doesn’t have the same conversational ring to it.

Have you published a response to this? :

Previously on this day

16 years ago I wrote Coming to America

I’m heading stateside tomorrow. I plan to spend three weeks soaking up the sun in Arizona.

16 years ago I wrote Hove rocks

Anyone from ‘round here will tell you that the city of Brighton & Hove is split between the hip, sleazy Brighton and the posh, old Hove (actually).