Created
August 21, 2011 12:27
-
-
Save raymondbutcher/1160544 to your computer and use it in GitHub Desktop.
iTunes plugin for Server Density
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
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