iTunes to MySQL
Posted by ark, ,
I've finally got something that will deal with my 43Meg iTunes Library.xml file! I found iTunes.py over at lazycat.org which I've modified to also load playlist as well as track information. It uses the most excellent pulldom python API which attempts to be more memory efficient than loading the whole dom into memory.

I then interfaced to a MySQL database with MySQLdb which was a breeze. I created a schema which would allow me to store more than one person's iTunes Library in the same database, this could lead to some interesting data mining! The SQL used to create the database is provided in sql.sql

The XML says it's UTF-8 put pulldom gets confused when it found some characters in it so I made it 'sanitize' the XML by stripping out non-ASCII characters, I know this isn't strictly a good thing, but I'll spend more time on that once I have it working more.

It's controlled by a .itdb.config file that you keep in your home directory an example one of those is provided too. I also provided an example small iTunes.xml library for development work. Loading that is a lot quicker than trying to reload your 40Meg XML file.

It's been tested on Mac OS X and Linux.

You can find the source over at:
http://code.google.com/p/wtwf/source/browse/trunk/itdb

Now I'm working on something to do something with the data. I'm using cheetah to write out HTML with data from the database.

Here's a sneaky peak at some of the expected output.


Of course once it's finished (or a little better) I'll be posting source here.

Comments