help me fix my corrupt uncorrupt itunes library
December 13, 2009 6:27 AM   Subscribe

My iTunes library is somewhat corrupt. The actual library file is fine, but I have about 700 (out of 14k) songs that are pointing to random files around my hard drive. Where do i start in repairing the file?

i have no idea how or when this all happened. all my music files are on a external drive, but all the music files in question point to random files on my system disk. song random file paths for example (from my itunes library.xml):
<key>Location</key><string>file://localhost/System/Library/Input%20Methods/SCIM.app/Contents/Resources/SCIM.help/Contents/Resources/zh_TW.lproj/sty/index.css</string>


<key>Location</key><string>file://localhost/usr/share/junit/javadoc/org/junit/Assert.html</string>


<key>Location</key><string>file://localhost/Applications/iCal.app/Contents/Resources/VS_Graphite_Divider.tiff</string>
I don't want to start my iTunes library over. I'd like to keep my ratings and play count. I looked at various iTunes scripts that report missing files but to iTunes these files aren't really 'missing', they just don't play. There's no good way to determine which files linked badly unless I try playing them and itunes just skips it over. I do have a backup of my itunes library.xml file from a year ago, would there be a way to merge the two together while filtering out the bad links?
posted by sammich to Computers & Internet (9 answers total) 2 users marked this as a favorite
 
Are you willing to roll up your sleeves? You could approach this with Applescript. Here's some pseudocode:

Tell Application "iTunes"
For each song in library
if the file of the song does not end with "mp3" and the file of the song does not end with "m4a" and the file of the song does not end with "m4p"
Add song to playlist "Bad Tracks"
Set the file of the song to "file://that/does/not/exist"
end
end Tell

You should wind up with a playlist containing all of your "bad" songs, and they should actually be flagged as missing. At this point, if you want to preserve your ratings and play counts, you'll need to manually "re-find" them; otherwise, just delete and reimport them.
posted by mkultra at 8:25 AM on December 13, 2009


I was going to suggest something like what mkultra suggests. Be sure to do this with a copy of your library in case you want to go back and start over later, though.

The iTunes library file does get randomly weird on occasion. My library's about the same size as yours and I have about the same number of songs that have a play count but no last played-by date. I've just learned to live with it and back up my library regularly to my dropbox so I can restore it if it gets more corrupt.
posted by immlass at 8:31 AM on December 13, 2009


iTunes lose track of files all the time. iTunes has even been know delete the files themselves. Apple doesn't worry since they'll give you the file again if you bought em' from Apple.

In theory, Apple's aliases use various data like path and inode for locating the target file, making them more sound than merely path. iTunes however loses files far more frequently than even for which even path changes would account, making me suspicious that Apple has retained this particular bug intentionally.

You can save just the ratings and play counts from ~/Music/iTunes\ Music\ Library.xml using grep's context options, but adding them back will require writing a script to process the xml, or maybe an other applescript.

Another trick is just periodically re-adding ~/Music and then checking your new music playlist.
posted by jeffburdges at 9:23 AM on December 13, 2009


Immlass and Jeffburdges... can you point to web-sites/links that confirm iTunes "losing files all the time" ?... cause I've never had that happen.
posted by jmnugent at 9:42 AM on December 13, 2009


iTunes lose track of files all the time. iTunes has even been know delete the files themselves. Apple doesn't worry since they'll give you the file again if you bought em' from Apple.

This is bogus. My iTunes library is many years old, and it's never so much as lost track of a single file. I "support" a lot of iTunes users, and this is not a problem I've ever heard of.
posted by Mwongozi at 9:51 AM on December 13, 2009


can you point to web-sites/links that confirm iTunes "losing files all the time" ?

I've had it happen a couple times. I probably did something wrong, but a lot of users seem to have this same problem. I think its file library system is far worse than the file management system of, say, Media Monkey.
posted by boeing82 at 10:01 AM on December 13, 2009


It's happened fairly regularly over the past several years on multiple Apple laptops under tiger and leopard, but I don't remember if the same problem occurred under panther.

I'd say my installations are not usually too messy since I use mostly unix software installed through Mac Ports, or previously Fink, for professional purposes. I've obviously considered whether extra codecs like Flip4Mac and DivX have confused iTunes, but the lost files are not the consistent file formats and may or may not have ever been played.

The total library size is 79gb in 13795 songs. iTunes does not copy files into the iTunes directory when added, but iTunes does keep the iTunes directory organized. All music is kept under /Music, the iTunes media folder location is /Music/iTunes/iTunes Music, and ~/Music is symbolically linked to /Music. I've never purchased songs from the iTunes Store, which is disabled for in parental preferences.

I just checked the current status by dragging ~/Music back into iTunes, which added 17 songs back into my recently added folder and all 17 also appear as dead links now, meaning iTunes has lost those 17 files. I did the exactly the same thing about 1 month ago, so that's november's lost files.

I expect the issue might resolve itself if iTunes moved files into the iTunes directory. Indeed, the problem likely originates with iTunes using a modified alias system that accounts for the iTune's directory structure. I've however never trusted iTunes enough to keep music in the iTunes Music directory, well hades confirms my misgivings. I'd assume many users keeping music outside their iTunes folder have dead song links in their iTunes libraries without noticing them, as iTunes will just skip over them.
posted by jeffburdges at 11:31 AM on December 13, 2009


Response by poster: mkultra: So I tried to see if I can get AppleScript to change the pathname location of the bad files to point to something that doesn't exist. But doing so, iTunes throws up the error "Disk some object wasn't found."

If I try pointing to an existing file on a drive (that's not a music file), I'll get an error: "Parameter error. number -50"

Even if I try changing some other information, such as the name of the song, i will still get the "parameter error". When I try this test on a valid, working song the command works fine.

If I point to a real mp3 file, iTunes will erase all the attributes of the original music file and replace it with the id3 information of the mp3 file I point it at

I get the feeling that AppleScript isn't going to be the way to solve this problem and that i'm going to have to do some fancy grepping.
posted by sammich at 10:49 PM on December 13, 2009


Did you re-add your iTunes Music folder yet? iTunes might reconnect with some files. Like I said, Mac OS X aliases use multiple tricks for tracking files, iTunes just does not exploit the full alias system.

An xslt script might be the easiest way to nuke all the missing files. A perl script using xml::twig could also handle purge them lickady split. Or even replace the bad location lines by good location lines if you re-add your iTunes Music folder.
posted by jeffburdges at 12:03 AM on December 15, 2009


« Older I'd like to help anonymous people stuck at the...   |   The Great Ecstasy of the Signer Herzog Newer »
This thread is closed to new comments.