I'd like to search for tracks on iTunes using a Python script on Mac OS/X. I found a way to access the iTunes application through:
iTunes = SBApplication.applicationWithBundleIdentifier_("com.apple.iTunes")
but I haven't figured out (yet) the way to perform searches. A little help appreciated.
Disclaimer: OS/X newbie here.
Note: I am not looking for ways to access the XML/plist database directly.
You might want to check out appscript (note, you'll need ASDictionary for online help):
>>> import appscript
>>> iTunes = appscript.app("iTunes")
>>> lib = iTunes.playlists['Library']
>>> for trk in lib.tracks():
... if re.search("test", trk.name()):
... print trk.name()
This might give you the most control by iterating over each item, but there's a much faster way too, by using applescript hooks to do the searching:
>>> trks = lib.tracks[appscript.its.name.contains('test')]
>>> print trks.name()
Check out these appscript usage examples as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With