Monday, March 10, 2008

Where did my collection go?

So I was trying to move my music collection in Amarok to a different machine. I simply moved all of the MP3 files from machine A to machine B, taking care to preserve the same path structure, and then copied the configuration files (~/.kde/share/config/amarokrc and ~/.kde/share/apps/amarok/* - for clarity, I'm using sqlite backend to store the collection). Then I opened Amarok on the second machine, only to find that my collection was empty. Now, this is not a situation that I'm unfamiliar with - the same thing happened one time when I upgraded Amarok, although somehow I managed to recover from that one. What confused me initially though was that I thought it might not be successfully reading the collection database file; however, after some searching and investigation I figured out what the real problem is and how to solve it.

Digging into the data structure of Amarok's collection.db (by running "sqlite3 ~/.kde/share/apps/amarok/collection.db"), it seems that Amarok records the device where each track is stored so that you can have tracks on removable devices, and they appear when you plug the removable device in and disappear when you unplug it. When running Amarok with the same collection data on another machine, the device that it thought contained all of my tracks (ie, one of my hard drive partitions) no longer existed and thus the collection was shown as empty.

Once you know what's going on here it's not hard to fix the problem, simply by fixing up the device links. In fact, in collections created in newer versions of Amarok (at least in 1.4.8 - my collection has been around for quite a few versions now) it seems to put the files against no device at all (device_id of -1). A few SQL statements later and I had simply cleared out the contents of the devices table and set all of the device_id values in other tables to -1 instead of a specific device, and voila - the next time I started Amarok my collection was restored :)

It seems to me though that there ought to be a nicer way of exporting your collection so you don't have to muck around like this. It might make a good summer of code project for someone... ;)

No comments: