views:

1720

answers:

2

I made an application that parse the iTunes library to retrieve its content. It works fine in most cases but if a user moved his library somewhere else than the default iTunes folder (see: http://lifehacker.com/238296/ultranewb--how-to-move-your-itunes-library-to-an-external-drive), then I need a way to find this path.

On Mac, I was looking into ~/Library/Preferences/com.apple.iTunes.plist. There is a setting called "alis:1:iTunes Library Location" but it contains several parameters all concatenated and converted to hexadecimal.

On Windows, I found this file "C:\Documents and Settings\\Application Data\Apple Computer\iTunes\iTunesPrefs.xml" that contains a setting "iTunes Library XML Location:1" but this one is encoded.

Any help would be greatly appreciated. Thanks!

+2  A: 

I can't help you with the Windows stuff, but on the Mac what you're seeing in that prefs file is old-school alias handle data. Take a look at or just use Chris Hanson's BDAlias class to convert it to a path.

http://github.com/rentzsch/bdalias

Ken Aspeslagh
Thank's a lot. I will give it a try.
Boris
+7  A: 

On Windows, the iTunes Library XML Location:1 entry in iTunesPrefs.xml is a Base 64 encoded Unicode string, so you'll need to decode it before you can use it. On my PC, it decodes to C:\Documents and Settings\Emerick\My Documents\My Music\iTunes\iTunes Music Library.xml.

It should be relatively easy to decode this value using your language of choice; your platform may even provide utility libraries that make this trivial. In C#, for example, the decoding function would look something like this:

static public string DecodeBase64(string encodedData)
{
  byte[] encodedBytes = System.Convert.FromBase64String(encodedData);
  return System.Text.UnicodeEncoding.Unicode.GetString(encodedBytes);
}
Emerick Rogul
Thanks I will give it a try! I saw the .pref file but wasn't sure how it was encoded.
Boris