I’ve been having fun over the last couple of days playing with a nice combination of SOAP, Applescript, Amazon, Drupal and iTunes.
The result of this unholy alliance is my Now Playing script, which is yet another of those publish-what-iTunes-is-doing-as-if-anyone-cared tools.
At the moment I’ve got an applescript with an idle loop that gets the current track info from iTunes, looks it up on amazon to get a picture, then writes the information out to a small html file.
I’ve then got a bit of PHP code in a custom Drupal block which reads in the html.
At some point it would be nice to merge these into one script, but I think that there might be issues with a perl script on the server talking to an application running logged in as another user (time for a bit more experimentation).
I’m really impressed at the ease with which one can make SOAP requests from Applescript. This stuff has apparently been around since 2001, but I’ve been so wrapped up with Championship Manager that I had no idea.
Thanks to Tim Jarrett, for some scripts which helped set me off in the right direction.
As it happens, his Amazon Handler script seems to be a bit out of date now, so after a lot of head scratching, I figured out how to do things using the latest Amazon SOAP api.
By way of a thank you, here’s some example code. I haven’t generalised things as much as Tim did, so this function is for a very specific job (look up a track and return urls for the amazon page and an image), but it should give you some idea:
on amazonLookup(trackName, bandName) try set soapParameters to ¬ { ¬ |SubscriptionId|:"1HT82XR9S43B5V8YDQ02", ¬ |SearchIndex|:"Music", ¬ |Title|:trackName, ¬ |Artist|:bandName, ¬ |ResponseGroup|:"Small,Images" ¬ } using terms from application "http://www.apple.com/placebo" tell application "http://webservices.amazon.com/onca/soap?Service=AWSECommerceService" set soapResult to call soap ¬ { ¬ method name: "ItemSearch", ¬ method namespace uri: "http://webservices.amazon.com/AWSECommerceServices/2005-02-23", ¬ parameters: soapParameters, ¬ SOAPAction: "http://soap.amazon.com" ¬ } end tell end using terms from set soapOutput to |items| of soapResult set itemList to |item| of soapOutput repeat with i in itemList try set a to the itemattributes of i if the productgroup of a is "Music" then if the artist of a is bandName then set imageURL to the |url| of the smallimage of i set trackURL to the detailpageurl of i return {ok:true, track:trackURL, image:imageURL} end if end if end try end repeat end try return {ok:false} end amazonLookup
It took me a long time to figure out exactly what parameters I was supposed to be supplying in the SOAP call (the Apple documentation is a bit sketchy), but once I did, it worked like a dream, and it opens up all sorts of interesting possibilities.
What you get back from the call soap call is a compound record which follows the same structure as the XML SOAP reply. From there it is easy enough to extract the information that you’re after.
As I mentioned, this code just gives a very specific example of one call to Amazon to do one thing. There’s a lot more you can do, and the Amazon documentation seems quite extensive.
Have fun…
I’m involved in the early planning stage of a couple of projects which might both describe their aims as “to create the next Hypercard”.
This has been an ambition of mine for the last ten years at least, but unfortunately it’s an ambition shared by an awful lot of other people, and so it has become a bit of a hackneyed phrase. Of course, what we definitely don’t want to do is create a Hypercard rip off. There are already some around, they are probably great, and I wish them all well.
What we want to do is to distill the essence of Hypercard - what it was about it which was so fantastic at the time - and apply those same principles to the environment we find ourselves in today.
One thing I’m surprised about is that I couldn’t find a concise description anywhere on the web of what exactly it was that made Hypercard great. As a result, here’s my first attempt: [What Made Hypercard Great?]. I’d be very interested to hear people’s comments.
Whatever I do, my Technorati Profile link seems to be producing errors. Not quite sure why.
I blame Kevin Marks (completely arbitrarily you understand). Hopefully he’ll read this post and fix it for me ;)
Update: I’ve deleted all the claims and started again… the JavaScript error was down to Drupal helpfully inserting a <br> tag in the middle of the Technorati script tag.
On the topic of Hypercard, there seem to be a few other interesting authoring tool projects around. I’ve listed a few below: anyone got any more I should look at?
Squeak has some pretty big names behind it.
PythonCard seems a way away from prime time, but sounds like an interesting project, with a good motto: “Simple things should be simple and complex things should be possible.”
The Skate project aims to recreate SK8, which was sort of like Hypercard on steroids, written in MCL.
Phase 2 of the great Elegant Chaos relocation is about to get underway.
As a result, the web site may be down for the next week or so. Normal service will be resumed as soon as possible…