Skip to content

Instantly share code, notes, and snippets.

@codiez
Created December 18, 2009 08:05
Show Gist options
  • Save codiez/259355 to your computer and use it in GitHub Desktop.
Save codiez/259355 to your computer and use it in GitHub Desktop.
'''
This script grabs the currently playing song from Itunes and generates a dict with the song details such as name, artist, album, genre etc.
You need the appscript library
'''
from appscript import *
it = app('iTunes')
tags = ['name', 'artist','album','genre','played_date','duration']
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))
try:
z = song_details['played_date'].name
song_details['played_date'] = ''
except:
pass
print song_details
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