[Pythonmac-SIG] Accessing the iTunes database directly?

has hengist.podd at virgin.net
Wed Dec 15 02:02:46 CET 2010


[Pythonmac-SIG] Accessing the iTunes database directly?
David Stokes wrote:

> Can the iTunes library database be accessed directly via Python?

No. Your only options are the Apple event interface and the read-only
XML file in your iTunes library.

> What I want to do are some fairly basic manipulations of the data but using the scripting API (from both appscript and AppleScript) was ridiculously slow; operations that took seconds in comparable manipulations of a SQLite database of a similar size took multiple hours.

Did you read the 'About application scripting' and 'Performance
issues' chapters in the appscript manual? Remember, Apple events = RPC
+ queries, not OOP. Remotely iterating over large data sets will
absolutely kill your script performance-wise. While certain tasks can
only be done via iteration and lots of small simple commands, e.g.
setting the name of every track in a 50,000-track library, plenty of
others can be reduced to just one or two commands by using more
sophisticated queries, e.g.:

   tracks_ref = iTunes.tracks
   info = zip(tracks_ref.name.get(), tracks_ref.album.get()) # 2 commands

not:

   info = [(track.name.get(), track.album.get() for track in
iTunes.tracks.get()] # 2*N+1 commands

If you're already familiar with how relational DB queries operate,
it's not so different (as that is where the original AppleScript
engineers nicked half their ideas from).

HTH

has
-- 
Learn AppleScript, 3rd edition, Sanderson & Rosenthal:
http://apress.com/book/view/9781430223610
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net


More information about the Pythonmac-SIG mailing list