Sat 15 Aug

Migrating iTunes to New OS

I recently switched from Vista to Ubuntu/Win7 due to truly abysmal performance. We're talking file copy rates in the tens of kilobytes, folks. Bad stuff. Anyway, I have switched over to a much better setup and am getting the kind of performance I am supposed to for the hardware I have. That said, I needed to move over my iTunes library to my new machine, without reimporting everything and losing all my playcount information.

Scenario: I had most of my music files on an external hard drive, but over the past year most of the music I'd bought off Amazon MP3 (a great service) or ripped from physical CDs was stored on my internal hard drive. I needed to copy my music on the internal drive to the external drive when I switched OSes, in addition to moving over the iTunes library itself.

Solution: First, let's understand how iTunes organizes your music. iTunes maintains an XML listing of all your songs, playcounts, etc, including a link to the actual song file somewhere on your hard drive (I noticed these links are URLs pointing to your local disk, so I wonder if I can move my songs to a webserver and have them accessible over HTTP; that would be a much more elegant solution to access-anywhere music than my previous SFTP setup). There is also a binary .itl file that maintains this information, and will overwrite any changes you make to your "iTunes Music Library.xml" file unless done through iTunes.

To make the transfer, we first copy our old "iTunes Music Library.xml" from our iTunes music folder, and store it somewhere safe (I renamed mine to "Old iTunes Library.xml" to avoid confusion). After doing this I moved all the music files stored on my internal drive to my external drive.

Next, I modified this backup copy to reflect the changed file paths for those files I moved from the internal drive to the external one. I used a simple find and replace command to replace the old file paths pointing to the internal drive to the new file paths that pointed to where I had moved the song files on my external drive. Since most were on the same place on my internal drive, organized in folders by artist, and since my external drive's music folder was organized in the same way, they all shared the same internal drive path ("C:\Users\shaddi\Music"), which could be find-replaced with the new path ("E:\Music", for me). Note if we were using Unix, we could do the find replace with a simple sed or perl script on the command line. In Windows World we have no such nice things.

On my new OS installation, I installed iTunes as normal, opened it up, and (importantly) deleted all the default playlists it gives you (those will be replaced when we reimport our library). Next, I selected "File > Library > Import playlist..." (yes, playlist: that is horribly named, no? We're importing /libraries/, not playlists!), specified the modified iTunes library I had created, and waited a few minutes for it to import. When it finished all my music was back the way I had it before, though I did have to rebuild my Genius database.

This technique also allows you to make bulk manual changes to your iTunes library. Just modify your library, delete the old one, and reimport. No more awful "Song Info" dialog!