iTunes Library Corruption

My 1.5GHz PBG4 has been painfully slow for the last month or so. While I’m game to replace it with a MacBook Pro (Core 2 Duo, baby!), we haven’t sold our old apartment yet, so new computers are verboten this month. Reasoning that a) it used to be reasonably snappy, and b) running a 100gb drive with 0-5gb free for a couple years could cause severe fragmentation, I copied almost everything off, repartitioned to get rid of my 10gb OS test partition (which has been very very useful, but is no longer needed for various reasons), and copied stuff back.

Unfortunately, there was a giant fly in my ointment. Since I keep an exact duplicate of my iTunes library on two other machines (via rsync), and the library was more than twice the size of my other OS & data files, I didn’t back up the music with SuperDuper! Instead I just skipped it, and copied it back from another machine after SuperDuper!ing the restore.

Thus begins my tale of iTunes woe. My 48gb 13k-song library was trashed. The iTunes DB appears to store and prefer FSIDs for the actual media files. An FSID (FSSpec?) is a file number, guaranteed to be unique for a file system (volume, partition, disk). Of course, when one recreates the file system and copies files back, they get new FSIDs. When I opened iTunes, it wouldn’t play music. I now believe this was because it was trying to start off by playing an ‘MP3′ entry from the Library (database) which actually pointed to a non-music file (presumably one which had picked up an FSID which previously belonged to that MP3 file).

iTunes has a subtle problem with ‘missing’ files. Although it can skip over missing songs while playing, finding the next song in sequence that is available and picking up there, when starting to play music, iTunes can’t get past a missing song. The solution (if you know what’s wrong, but unfortunately there is no warning or indication of the problem — iTunes just does nothing when exhorted to make music) is to play a file which is actually present and correct, after which things work okay. And then to use something like the excellent Super Remove Dead Tracks AppleScript from Doug’s AppleScripts for iTunes.

Making things more difficult, iTunes kept hanging while attempting to update my iPod (Spinning Pizza of Death), and stopping after I started playing one song (so there was more wrong than just the won’t-start behavior, but I don’t know what). I had no music to listen to while I worked on the problem! Combined with having no iTunes while SuperDuper! did its thing, I was already going a bit (more) batty (than usual).

After spending a totally annoying amount of time thinking the iTunes DB & preferences were completely corrupt, I realized that of my almost 13k “tracks”, a little over 5k were the correct files, but more than half were pointers to the wrong places. Note that they all looked correct in iTunes, which had all the playlist, rating, etc. info in the DB (ratings are only in the DB — they aren’t stored in the files, which irritates me every time I lose the DB — no, this wasn’t the first time).

After opening a bug report with Apple, sending an Apple System Profiler report, 3 samples, and a copy of my iTunes Library file, I figured out what was wrong. I used BBEdit to strip out all the bogus Locations from an iTunes Library export, which meant iTunes unfortunately completely ignored those files, but it did re-import all the ones with good paths. This gave me a 5k-song library with ratings. Next I dropped my whole music folder on iTunes and lett it import, scan for gapless playback, scan for volume level, and scan for album covers, I had a mostly-working iTunes again, with 8k+ unrated songs and holes in all my manual playlists. Fortunately, I was able to create Smart playlists ‘1′, ‘2′, ‘3′, ‘4′, & ‘5′ from the old Library (containing the bad FSIDs), which imported mostly successfully. After rating unrated songs according to those playlists and a bunch manually, I had a hundred unrated songs, which was much more reasonable.

YUCK!


Update, 2006/12/16: Feh. Some of the FSIDs ended up pointing to real sound files, which means after I dropped the whole folder onto iTunes, it had duplicate entries for those tracks (one pointing to the right file, and one pointing to the wrong file). Fortunately these were pretty easy to recognize, because I had pairs of one rated (bad file) and one unrated (’new’ file from the drop), but I had already ‘cleaned up’ a few of these before I realized that I still had bad links. Additionally, since iTunes is set to “Keep iTunes Music folder organized”, for a few files that pointed to the wrong MP3s, iTunes helpfully renamed and re-tagged those MP3s to match the MP3 it ‘thought’ they should be. This means I have a few unidentifiable files with the wrong names. For some I can tell which is right by playtime, but for others I can’t know which is which, and there’s no sign of which files are missing from the library.

RSS feed for comments on this post · TrackBack URL

Leave a Comment

You must be logged in to post a comment.