February 4, 2009

Understand iTunes XML: Port Your Music Library from Windows to Mac

Filed under: learnings, programming, side project, xml — Lindsay @ 9:29 am

(Created February 2009, Updated July 2009)

Introduction

This is a tutorial designed to help you port your iTunes library from PC to Mac (or visa versa) without losing your Playcount and Rating information.  I make several assumptions about the audience in writing this tutorial:

  1. You have a basic understanding of XML.
  2. You are not scared to read and update XML code.
  3. You do not want to lose your Playcount and Rating information.
  4. You are able to move your actual music files from 1 machine to the other without changing the general hierarchy of your file structure.

Now here is the warning for those of you that still are on the fence – this isn’t easy-peasy – we’re not selecting some checkboxes and radio buttons, we’re looking at the code where iTunes stores information about each song.


Background

In the Fall of 2005 I did a project called Playlist Generation & Download that involved creating iTunes playlists using the iTunes XML namespace.  I’m hesitant to use the word ‘namespace’ because of iTunes XML’s poor structure.  We enabled mobile and desktop applications in a service-oriented architecture to provide search, discovery and playlist generation using XML schemas.  In implementation, a user could upload and share iTunes playlists, then download others based on genre and artist search.  This tutorial was built based on the knowledge I gained doing this project 4 years ago.


1. Export a single playlist, view it’s XML format

iTunes stores all the data about each song into XML files; when you select Export Library or Export Playlist, the program will allow you to save the output as an XML file.  Lets get started by looking at a sample XML file.

  1. Select a playlist, preferably a small one (< 25 songs), and where the songs all reside in the same folder (a particular artist’s album would work really well for the “training wheel’s” version of this tutorial)
  2. Navigate to File> Libary > Export Playlist
  3. Save the XML file somewhere you can find it.

Open up the file in a text editor.  The first section of the file is the usual introductions:
itunes header info
If you’ve worked with XML before and you have never seen the iTunes XML, then you’re probably a little startled to see its poor format.  For those of you that don’t know right away what is wrong, it’s the fact that every variable is stored in some tag called <key></key> and its value stored in a tag such as <integer> or <string>.  If I were to rewrite the first key, it should look like <Major Version>1</Major Version>.  The iTunes people would have saved themselves a bunch of time if they paid attention in XML Bootcamp!

2. Locate the “Music Folder” path information

In this snippet of code, the most important piece of information is:

<key>Music Folder</key><string>file://localhost/Users/lindsay/Music/iTunes/iTunes%20Music/</string>

The <string> value is the location of your iTunes Music folder, and in this case, this is the Mac format.

Instructions:

  • Determine the location of your Music Folder in both your Mac and PC
  • Copy and paste these locations into a text editor so you can compare the differences between the two.
  • If you’re moving from a PC to a Mac (and try this first with your sample playlist):
  1. Export your Playlist on your PC – lets call this Windows.XML
  2. Change the Music Folder <string> to use the Mac location (path info), making sure the format is in a Mac format.

3. Locate the song “Location” path information.

Now lets look at the XML for each song.  Each song in your library or playlist XML file has a few lines of XML to describe its properties; two of these lines contain the play count and the star ratings, exactly what we DONT want to lose.  Here you go:

itunes song xml

But, the only line we care about is the fourth line from the bottom:  Location.

Instructions

  1. Copy the folder in which your playlist’s music resides from 1 machine to the other.  In my case I would take the Asher Roth album, and move it from my Music folder on my PC to my Music folder on my Mac
  2. Find the new path information for this folder.  On my PC, it’s something like “C://Documents and Settings/Music/…”, and on my Mac it’s file://localhost/Users/lindsay/Music”
  3. Compare the two location/path information to see where they defer and where they don’t.  For me, its the path information up until the Music folder.
  4. For the first song in your XML file, locate the location information.  Cut out “C://Documents and Settings/” and paste “file://localhost/Users/lindsay”.  Verify that the path information for the song’s new location looks correct.
  5. Do a Find/Replace on the entire file – Find: “C://Documents and Settings/” (the original path information), Replace with: “file://localhost/Users/Lindsay/” (the new path information)
  6. You only want to do this Find/Replace because every song has a unique ending (the actual .mp3 name and file).

4.  Save and Move the Playlist.xml file to your new machine and upload

If you’re playlist folder is on your new machine in the path that you directed the Playlist.xml file to, then all you need to do is the following:

  1. Open iTunes – Navigate to File > Library > Import Playlist
  2. Browse and Upload your Playlist.xml file
  3. The Playlist should appear in your list of playlists, and the songs should now be in your iTunes
  4. Verify that the play count and ratings are intact.

5. Don’t delete the playlists

The final note is that you should not delete these new playlists.  If you delete them, you may lose some of your song’s information

Direction Reduction:

1.  Export your iTunes Library on your Windows machine.

2. Open the file in a text editor; change the directory for your Music Folder and change the directories for the location of each song (a simple Find and Replace should work if you have correctly maintained your music folder hierarchy)

3. Import the XML file into your iTunes on your Mac machine.


Final notes to make your life simpler:

This is a really simple thing to do if your library is less than 1300 songs.  If your library is like mine (9000+ songs) then you will need to separate your iTunes music into manageable sized playlists and export and edit each playlist.  I did this by creating Smart Playlists for each letter of the alphabet related to Artists.  It takes longer to do this on a playlist-by-playlist basis, but you’ll save your processor a lot of time and stalling (I had a 4GB processor that couldn’t handle the XML file for my entire library). I think total, this took me 2 hours to do. That’s 2 hours to save me the 30+ hours I would spend deleting duplicates and adding ratings if I had to start from scratch.

Your life will also be easier if your music happens to be on an external hard drive because you then don’t have to migrate the music too, just the data about the music.  This was my situation, but probably is not the case for most of you.

Again if you can move the actual files from your Windows machine to your Mac machine without changing the hierarchy, then migrating your library will be much simpler in the long run.

If you have any questions, leave a comment and I’ll be happy to help out!

Related posts:

  1. Signs of San Francisco
  2. A Class I Wish I Could Have Taken
  3. Working with Photoshop: Uncheck Embed Color Profile Save for Web & Devices

4 Comments »

  1. Kartik Garg

    Thanks for the iTunes XML crash course. Is there any way to fiugre out how iTunes stores album art location? More importantly, can I use this XML template to also point to my album art folder?

    Comment by Kartik Garg — February 11, 2009 @ 10:49 am

  2. Lindsay

    Kartik – I looked at some exported playlists and cant seem to find the artwork location. Sorry!

    Comment by Lindsay — February 11, 2009 @ 12:43 pm

  3. Unfortunately, Jon, that&#8217;s what Health Care is Like &laquo; Second Thoughts

    [...] to the ANSI X12 837 data format, which is in EDI. Most of you know that I’m a big fan of XML over the legacy data formats, and in agreement, my team has bemoaned this project as a necessary [...]

    Pingback by Unfortunately, Jon, that’s what Health Care is Like « Second Thoughts — August 17, 2009 @ 8:47 am

  4. Alex Forbes

    Great writeup, and thanks! I’ve edited my XML before for my PC machines, but had been out of the Mac loop for some years when I got this new Mac. I probably would have forgotten the file:// part…

    Comment by Alex Forbes — November 21, 2009 @ 10:43 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment