Created
December 18, 2009 19:48
-
-
Save codiez/259714 to your computer and use it in GitHub Desktop.
Post the currently playing song automatically to twitter, use as part of a service automator workflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Automatically post the currently playing track to twitter | |
Create an Automator service workflow to use | |
''' | |
import sys | |
from appscript import * | |
from os import popen | |
username='' | |
password='' | |
it = app('iTunes') | |
tags = ['name', 'artist'] | |
if it.isrunning(): | |
state = it.player_state.get() | |
if state.name == 'playing': | |
song_details = [eval('it.current_track.' + tag + '.get()') for tag in tags] | |
song_details = dict(zip(tags, song_details)) | |
url = 'http://twitter.com/statuses/update.xml' | |
message = 'listening to %s by %s' %(song_details['name'], song_details['artist']) | |
curl = 'curl -s -u %s:%s -d status="%s" %s' % (username,password,message,url) | |
pipe = popen(curl, 'r') | |
else: | |
print "Itunes is currently:", state.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment