I use iTunes. I have an iPod. They are totally awesome, and have radically contributed to my ability to enjoy my music collection. See, when I was in college and high school, I had an income but no bills. I suppose that about 75% of my income went to the purchase of CDs. I have about a thousand CDs, now. It's hard to listen to them effectively, because sometimes an album is all crap, save for one or two good tracks. Or sometimes I've bought an album and shelved it without forming a good opinion. iTunes and the iPod let me access all 15000 songs easily, leaving metadata on them to remind me what I like, what's good for the gym, and how many times I've listened to "We Love Deez Hoez" over and over.
I made a playlist called "The Rating Queue," configured to update with unrated songs from genres I might listen to at work or while walking around. As I listened to music on my iPod, I rated it. Over the last five months, I built up about five or six thousand ratings.
Ratings are stored in two files: the music library and the XML music library. The XML music library is for unknown use, but it's convenient if you want to parse the data. I've guessed it's just for data access by impatient third-party apps.
I have a little bash script called 'itl' that I use to swap out the music library files and re-symlink the folders that hold my music. That way I have one library for my work share, one for my laptop's hard drive, and one for the big share at home. It's a quick and dirty hack, but it works.
At some point in the past, I did something like remove the symlinks for itl and let the files live directly in place. I don't know what or when. Suffice it to say that when I ran itl for the first time in ages, I deleted my music library files. All my play counts and ratings were deleted.
That shouldn't have been a big deal; after all, I'd made a backup copy of the file for playing with Mac::iTunes. But I had just deleted it while reorganizing.
Well, failing that, I have a large number of ratings on my iPod. So I could resync. But my iPod was in California for repair.
Ok, so I could restore from backup! Too bad I only ever backed up my server, never my workstation. ("Everything important is from CVS, right?" I was so naive.) Part of the irony is that I had deleted the test copy of the music library during a transfer of all scrap files from my server to my laptop, done so that I could start backing up the laptop instead of the server!
I knew that I'd sent a copy of a library, some time ago, to iTunesRegistry.com; I opened Safari to see if I could just download that XML. I couldn't connect! They'd gone under!
Well, I was really not happy about this development, but once it was clear that there would not be a solution in the next ten minutes I went out cycling. When I got home, I found that iTunesRegistry
So, now the only problem became loading the tracks. Well, it wasn't really easy to find a correlation between the database entries and my repopulated library. I could've looked for Genre-Artist-Album-Song, but I decided it would be easier to use filesize. I only found about 20 songs in my library that had identical filesize, and I was willing to live with that. I sat down and quickly learned enough AppleScript to do the job. Of course, I didn't want to read in, parse, and update the data with AppleScript! I wanted to use Mac::Glue.
This did not work out well. I spent more than an hour hitting my head against the wall, trying to get an array of "track" items from the "library playlist" item. I just couldn't do it! Finally, tired and frustrated, I opted for the worst possible solution: generate AppleScript with perl and pass it to osascript(1). That's right, four thousand system calls passing something like "tell iTunes to set the rating of every track in library playlist whose size is $size to $rating"
It's been running since 22:30 last night, and it was about half done when I left for work this morning. I just don't care about elegance anymore. I want my music rated and my iPod repopulated. That's the good news, by the way: I got a brand new iPod from Apple yesterday, sent as a replacement.
Once this is over, I'm going to investigate the Mac::Glue problem. I would've used Mac::iTunes, but the CPAN version is ancient and my last experience with the CVS version was still iffy. I'm more excited than ever, now, to help bdfoy polish it up. (When is he back, anyway?)