iTunes library, fixing a broken one or moving one

find your Music folder/directory where these files live: you are looking for iTunes Library and iTunes Music Library.xml The XML file is a backup of the other file, which is the one iTunes uses: iTunes Library: data iTunes Music Library.xml: XML document text Move the iTunes Library file aside (rename it, put in your home directory, whatever)…. An example: <key>Location</key><string>file://localhost/private/Network/Servers/shuttle/usr/local/share/mt-daapd/media/Abbado_Berliner%20Philharmoniker/Mahler_%20Symphonie%20No.%205/01%20Trauermarsch.%20In%20Gemessenem%20Schritt.%20Streng.%20Wie%20Ein%20Kondukt.m4a</string> A quick and dirty way to do it on the command line, ie, in the Terminal?


I see some discussion about fixing busted iTunes libraries, either when moving one on the same computer or migrating to a new one. Here’s what I have found works for me.

Bonus: no slow AppleScripts or payments (donations cheerfully accepted and squandered). After almost 3 1/2 years more than four years, this continues to be a widely-read posting and still seems to work. I thought it was made obsolete with iTunes 8 or somewhere along there… As it’s been viewed more than 111,000 times and been found useful a few of those times, I wouldn’t object to a donation. But rather than spend your money, you could do me a favor and help yourself at the same time. Click that link and if you buy something at Amazon.com, they’ll send me a penny, maybe more. No obligation but also no cost to you.

As an aside, if you are going to comment along the lines of “I just moved my music from one Mac to another and nothing broke so why is this so complicated?” please don’t bother. The title specifically mentions a BROKEN library, you dig? Or perhaps your library has outgrown the current location and you want to move it but retain access to it as your primary library and keep all your playlists and history. That’s what this post deals with, not replicating a working installation, but changing one to suit a new environment or fixing a botch attempt at it. Peace.
And for goodness’ sake, read all the comments: some good stuff down there. Sadly, I had to throw away all the comments, as I disconnected them from the posts they were in response to.

First, what I have discovered about how iTunes manages music collections. There are two files it uses, one that is binary (ie, machine readable for faster performance on searching, sorting, add/edit/delete operations) and one that has the same information but in a human readable format (for a certain subset of humans who can read XML natively). The XML file is written from the binary file as a backup (check the dates to confirm).

Picture 16.jpg

iTunes will try to open the binary file when it starts up and if it’s not readable, it will re-create it from the XML file. That’s what we’re using to fix the damage or make any sweeping changes.

First, close iTunes. You’ll be working with files it uses/writes to and you’ll muck things up if you makes changes to files it has open and then your changes get clobbered, leaving the binary and the backup unusable. Don’t do that.

  1. find your Music folder/directory where these files live: you are looking for iTunes Library and iTunes Music Library.xml
    The XML file is a backup of the other file, which is the one iTunes uses:
    iTunes Library: data
    iTunes Music Library.xml: XML document text
    [NB for Windows users: you will be looking for iTunes Library.itl and iTunes Music Library.xml.]
  2. Move the iTunes Library file aside (rename it, put in your home directory, whatever). Create an empty file with the same name (or simply mangle a copy of it: seriously: this is where the backup copy comes in). If you are in the Terminal, you can just use touch(1), as in touch iTunes\ Library. You can also just open a file in whatever other editor you like and save it as iTunes Library.
  3. You’ll need to edit the XML file, in a text editor, not a word processor (not Word, as if I have to explain that). vi, emacs, pico, nano, TextWrangler, BBEdit, TextMate on the Mac side, NotePad/WordPad, et al on the Other Side. You are going to search and replace the current location with the new one. Every file/track/song has it’s own stanza in that file and within that, there is a Location key. You need to replace the old one — as an absolute path — with the new one.
    An example: <key>Location</key><string>file://localhost/private/Network/Servers/shuttle
    /usr/local/share/mt-daapd/media/Abbado_Berliner%20Philharmoniker/Mahler_%20Symphonie%20No.%205/01%20
    Trauermarsch.%20In%20Gemessenem%20Schritt.%20Streng.%20Wie%20Ein%20Kondukt.m4a</string>
    Picture 17.jpg
  4. A quick and dirty way to do it on the command line, ie, in the Terminal?perl -pi -e.backup s|oldpath|newpath|g iTunes Music Library.xml
    perl -pi.backup -e s|oldpath|newpath|g iTunes Music Library.xml

    This will create a backup file (cleverly called “iTunes Music Library.xml.backup”)

  5. Now, test it. iTunes needs to find that iTunes Music file and since it can’t read it (it’s empty or damaged), it will create one from the backup you just edited. Give that a minute or three to complete. See if your files are found and playable. This should also keep your playlists (which are just another XML stanza with the elements being track ID numbers).

This has worked for me more than once and if it’s reproducible, it should work for you. But note that I recommend a backup copy of the XML file. You can go back and re-do it from scratch if you get into trouble.

And I expect this is extensible in many interesting ways, like merging libraries from different users (something with diff and patch, perhaps?), switching from one repository to another (maybe a large home repository and a smaller traveling one). I’m not clever enough to figure those out, but if anyone else does, I’d love to hear about it.

[update] This looks interesting:

I had to do some more things with my iTunes library lately – like extracting all that ratings and exporting them into a new music player software I liked to test. I therefore wrote myself a little tool in C# that does the job of reading in the whole iTunes library and giving you programmatically access to that library. It only needs to have read access to the Mediathek.xml file iTunes stores in it’s music folder and you from there on can work your way through the bazillions of music tracks you may or may not have in your library. It even does the find-and-replace job a bit easier than the solution mentioned in the article above.

quote of the day

via email: It’s kind of like how I remember when the only place you could get organic cellphones was at the neckbeard freetard web site, and the phones kind of sucked. But there were people who bought them anyway, because they believed that things could be better.

via email:

It’s kind of like how I remember when the only place you could get
organic cellphones was at the neckbeard freetard web site, and the
phones kind of sucked. But there were people who bought them anyway,
because they believed that things could be better. [RJL20/elsewhere.org]

zealotry

[From 5 reasons to avoid iPhone 3G – Free Software Foundation ] The FSF is something I would like to support but the claims they make are so extreme , I just can’t. There’s an underlying elitism there, that only people who can program computers should have them (can anyone argue that without shrinkwrapped software, we would see fewer computers and likely a lot of industries might never have been born (is there a freeware DTP application that rivals PageMaker or it’s successors?

[updated Fri Jul 18 12:36:24 PDT 2008]: As the comments illustrate, I can’t argue against a position I don’t understand. Don’t like the iPhone, iPod, whatever? Don’t buy one.

Some helpful hints:

  • Tell people what the trade-offs are when they “buy” these new devices/services (buy is in “quotes” since increasingly, we are buying access or a license to use something, rather than an actual thing).
  • Explain what happens (not what might happen or what it means in moral terms) when these fail or the hidden pitfalls of the relationship are exposed.
  • If possible, show people where they lose money, as opposed to freedom or other philosophical principles: the man in the street understands one better than the other and being unwilling or unable to frame your argument in terms that are mutually understood means you’re wasting your time.

As skeptical as I am of the free market and consumerism, it makes me itchy to find myself defending it against an agenda I don’t understand. I don’t think the free market is an unalloyed good, as I don’t believe it is truly free. It’s a rigged game. The Invisible Hand is in my wallet.

As best I can tell, the LPF/FSF/GNU folks admit to no such weaknesses or trade-offs. The response will be that I need to read all their back-catalog of position papers and manifestos. <sigh>

Gruber points to this from the FSF:

Wait, locked up? Prison? It’s a phone. Aren’t we being a little extreme?

[From 5 reasons to avoid iPhone 3G – Free Software Foundation]

The FSF is something I would like to support but the claims they make are so extreme, I just can’t. There’s an underlying elitism there, that only people who can program computers should have them (can anyone argue that without shrinkwrapped software, we would see fewer computers and likely a lot of industries might never have been born (is there a freeware DTP application that rivals PageMaker or it’s successors? For that matter, I’m still looking for an office suite that works as well as the Leading Brand . . . ) Would the internet be as ubiquitous as it is without the millions of commodity (read: Windows) PCs out there? Hmm, maybe it would be better if it wasn’t . . .

I think the bottom fell out when I saw the bit about Steve Jobs hating competition. He introduced a new phone platform in a mature market against a whole array of entrenched players — Nokia, Motorola, LG, Samsung, RIM, Palm — and seems to be doing quite well. There were digital music players before the iPod: where are they now? I think he craves competition, or he might have been content to run Pixar and count his money. And there is something a little disingenuous about a MacArthur grant winner arguing about business models. $240,000 over 5 years isn’t a bad wage. For someone obsessed with fairness, how fair is it for a grant recipient to offer products and services that compete against organizations that are not grant-subsidized?

Seriously, I think there is a need for the work the FSF is doing but I wish they could make their case without the exaggerated claims.

Continue reading “zealotry”

Jack Shedd is an honorable man.

The author and proprietor of Big Contrarian just sent me an Amazon gift card for the simple act of noting a small error on one of his recent posts. A simple “thank you” would have done (he says, as he greedily lingers at Amazon.com) but I’ll make good use of this.

The author and proprietor of Big Contrarian just sent me an Amazon gift card for the simple act of noting a small error on one of his recent posts. A simple “thank you” would have done (he says, as he greedily lingers at Amazon.com) but I’ll make good use of this.

Thanks.

is this for real?

The dean of Massachusetts School of Law at Andover is planning a September conference to map out war crimes prosecutions, and the targets are President Bush and other administration officials. The dean, Lawrence Velvel, says in a statement that “plans will be laid and necessary organizational structures set up, to pursue the guilty as long as necessary and, if need be, to the ends of the Earth.”

Imagine the trial, let alone a guilty verdict and a hanging. It’s unpossible . . .

The dean of Massachusetts School of Law at Andover is planning a September conference to map out war crimes prosecutions, and the targets are President Bush and other administration officials.

The dean, Lawrence Velvel, says in a statement that “plans will be laid and necessary organizational structures set up, to pursue the guilty as long as necessary and, if need be, to the ends of the Earth.”

Other possible defendants, he said, include federal judges and John Yoo, the former Justice Department official who wrote one of the so-called torture memos.

“We must insist on appropriate punishments,” he continued, “including, if guilt is found, the hangings visited upon top German and Japanese war criminals in the 1940s.”

[From Law School Dean Calls Conference to Plan Bush War Crimes Prosecution | ABA Journal – Law News Now]

the “serious left” gets its knickers in a knot — again

You’re under no obligation to moderate comments, so why invite people to speak their piece and then toss it in the Memory Hole? That said, this is entertaining, to see the humorless and uptight “serious left” get their tightie whities in a bunch about a satirical magazine cover.

The serious lefties over at the Washington Monthly think this cover will read like scripture to most people.

Blog_New_Yorker_Obama.jpg

[From The Washington Monthly]

And they’re moderating comments, so I have enclosed mine below.

Dear Moderators,

ya know, it really bollixes things up when you remove comments that other people have responded to. You’re under no obligation to moderate comments, so why invite people to speak their piece and then toss it in the Memory Hole?

That said, this is entertaining, to see the humorless and uptight “serious left” get their tightie whities in a bunch about a satirical magazine cover. For those of who say the art in question is not satire, it might help to refamiliarize yourself with the word and its meanings:
1. the use of irony, sarcasm, ridicule, or the like, in exposing, denouncing, or deriding vice, folly, etc.
2. a literary composition, in verse or prose, in which human folly and vice are held up to scorn, derision, or ridicule.
3. a literary genre comprising such compositions.

And confidential to Albert Champion, the New Yorker does indeed have a masthead and many ways to contact them. Look harder. Also, Condé Nast left us in 1942, so I doubt any boycott of his magazines will matter much to him.