Skip to content

Instantly share code, notes, and snippets.

@raymondbutcher
Created August 21, 2011 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raymondbutcher/1160544 to your computer and use it in GitHub Desktop.
Save raymondbutcher/1160544 to your computer and use it in GitHub Desktop.
iTunes plugin for Server Density
from ScriptingBridge import SBApplication
class ITunes(object):
"""
Display the total duration (in hours) of your music libraries in iTunes.
This is admittedly pretty dumb.
"""
def __init__(self, agentConfig, checksLogger, rawConfig):
self.agentConfig = agentConfig
self.checksLogger = checksLogger
self.rawConfig = rawConfig
def run(self):
iTunes = SBApplication.applicationWithBundleIdentifier_('com.apple.iTunes')
if 'not running' in str(iTunes):
data = False
else:
data = {}
for source in iTunes.sources():
for playlist in source.playlists():
if playlist.name() == 'Music':
seconds = playlist.duration()
hours = '%.2f' % (seconds / 3600.0)
data[source.name()] = hours
return data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment