[Pythonmac-SIG] Accessing the iTunes database directly?
Ned Deily
nad at acm.org
Tue Dec 14 23:03:22 CET 2010
In article <21b38dbc-8071-6179-89c7-b9cbb050af9a at me.com>,
David Stokes <stokes at mac.com> wrote:
> Can the iTunes library database be accessed directly via Python? 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. I had thought I'd heard that iTunes uses --
> or once used -- SQLite, but either it has changed or I was just looking in
> the wrong place.
>
> If nothing else, I suppose I can use an XML export of the
> library data and then re-import it.
Keep in mind that, depending on how your iTunes library is configured,
changes to a track's metadata may cause iTunes to update the metadata in
the music file (mp3 tags, etc), which may take a long time to rewrite
each affected music file. That can make mass updates *very* slow
regardless of how you do it: manually or through a scripting interface.
You can parse the iTunes XML file easily in Python but, AFAIK, the only
ways to then update the iTunes data are by either reimporting the
modified XML library file, which might cause you to lose some
information, or through the scripting API; I don't know of any public
APIs to iTunes internal DBs. If you don't care about the tags in the
music files themselves, you may be able to inhibit the file updates by
experimenting with some of the iTunes preferences or possibly by
temporarily changing the music files' permissions.
--
Ned Deily,
nad at acm.org
More information about the Pythonmac-SIG
mailing list