Dave Burke : Freelance .NET Web Developer specializing in Online Communities

iTunes Mod: From iTunes to SQL Server

The first step in posting my iTunes Library to my blog as a CS Mod was the get my iTunes library data into SQL Server.  iTunes has an "Export Library" menu function, which exports the complete library to XML.  Okay, now what?  I read and tested several (non .NET) approaches to transferring the iTunes Library.XML file to SQL and to display the iTunes library on a web page, but most used XSLT.  Sorry, but that's just stupid. 

Then I discovered THE article, a Code Project piece by Alexander Kojevnikov titled sqlTunes - query your iTunes library.  This VS2005 project reminds me of what they say about pornography, though in this case it's about beautiful code.  "I know it when I see it..."  This code is beautiful.  It's a Windows Forms app and even if you're not interested in migrating your iTunes Library to SQL Server you would see a lot of .NET sweetness in this source:  liberal and smart use of generics, multi-threading, writing to the Eventlog, executing a sql definition script using Assembly.GetManifestResourceStream()...just a darn beautiful little bundle of VS2005 C# code.

Instead of XSLT, AK used XmlTextReader into a StreamReader, then with a Dictionary<string, object> for each record (track) and a Dictionary<string, int> for the keys and their length, he dynamically created the SQL insert script.  Very fast, too.

I made some changes for the longterm: removed spaces from SQL field names (I hate field name spaces), modified the structure of the table a bit, added some clean-up code for library items I didn't want to import to the database, etc., but otherwise the app was an extreme pleasure to use.

Mr. Kojevnikov, you rock!

Technorati Tags: , ,


Comments (0) | Post RSS RSS comment feed

Posted on 12/29/2005 8:23:00 PM by Dave Burke
Categories: .NET
Tags:

Related posts


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke