There's a notable lack of AppleScript support in the Spotify player, and I (along with many others) would like to do interesting things with Spotify. Things like, updating my Adium status with what I'm listening to on Spotify, sticking what's now playing in the office on an LED message panel, and doing other interesting mashups.
So, here's a workaround, using Spotify's built-in scrobbling feature. What I'm attempting to do, is capture the network packets that are sent from the Spotify player to Last.fm's API, and extract what's now playing by inspecting the HTTP request.
Yep, it's all pretty backwards, but I think it's the only viable workaround, until either Spotify adds an AppleScript dictionary, or Last.fm provides some kind of real-time webhook interface.
-
Install scrobbify from the Python Package Index, e.g. using easy_install:
$ easy_install scrobbify
-
Be sure to enable scrobbling to last.fm in your Spotify player preferences.
-
Use scrobbify like so:
import scrobbify, sys def cb(now_playing, data): sys.stdout.write("Now playing: '%s' by '%s'.\n" % (now_playing['t'][0], now_playing['a'][0])) sys.stdout.flush() scrobbifier = scrobbify.Scrobbify(cb, interface='en0') scrobbifier.start() # Exit gracefully... try: while True: time.sleep(2**20) except (KeyboardInterrupt, SystemExit): scrob.stop()
I'm fairly certain the code is sub-optimal right now, so feel free to leave me some feedback, via email or even twitter. :)