You are here: Start -> this page

Relocation of a non-standard iTunes library structure

Since I have a lot of automatic playlists based on play count, not losing the play count data was decisive when I had to move my iTunes library from a workstation to a server. However, if you just move the folder and export/import the iTunes library, exactly one thing is lost, the play count. The way to keep the play count intact is to first change the location of the iTunes libary in your prefs, and then use the Advanced -> Consolidate Library menu option. However, this method requires that you have organized your music the way Apple suggests.

For me, the Apple way of organizing my music is not flexible enough. In my music folder, I have a few subfolders, e.g., My albums, Demos, Bootlegs etc. The reason for this is that I want to apply different sharing restrictions on each directory. For example, the My albums-folder everyone on the computer may read, the Demo-folder is OK to share on Gnutella or DC, but no one but me must be allowed to listen to my bootlegs. The folders are organized like this:

Music
My albums (below I will refer to this level as the root)
Name of artist/composer
Album name
01. Trackname.mp3
02. Trackname.mp3

I handle compilations slightly different, I have a separate folder for them named Compilations:

Music
My albums
Compilation
Album name
01. Artistname - Trackname.mp3
02. Artistname - Trackname.mp3

In the compilations case, I do not think it makes sense to have a a lot of artist folders with only one track in them. I typically have a lot of compilations from independent record companies with a lot of bands that never released more than an occasional track or two.

The big questions now is how to migrate this setup and keep the play count. I found a way that worked to about the 95% level (see caveats at the end about the missing 5%).

First one has to be aware of how iTunes traces the tracks in its library. By experimenting a little, I found that first it looks for inodes and as fallback if the inode is not available, it looks for the file's path. I don't know if there are any further fallbacks.

Secondly, one also has to be aware of what iTunes does when it consolidates the library; when consolidating the library, iTunes looks at the ID3 tags of all tracks in its library it can find, and creates a hierarchy like this:

Music
Name of artist/composer
Album name
01. Trackname.mp3
02. Trackname.mp3
Unknown artist [for tracks without ID3-tags]
Unknown album
Trackname.mp3
Trackname.mp3

Please note that the My albums-level is removed. In addition, iTunes leaves the name of the tracks untouched. Simply consolidating the libary would, in my case, therefore have caused an unacceptable result, since the first level of separation (My albums, Demos, Bootlegs and a few more) would have disappeared.

The solution was to consolidate one root level (My albums, Demos, Bootlegs etc) folder at a time. However, it was not that easy. I realized this after my first attempt, when I simply moved the other root level folders to another location on the same partition and found that iTunes still kept track of the files in these folders, due to their inodes, and therefore, consolidated them toghether with the My albums-folders.

To force iTunes to temporarily forget about the files in the other root folders, I had to duplicate them, and delete the original folder. Now I had something that looked like this:

Music
My albums
Demos (copy)
Bootlegs (copy)

Consolidating now leads to only the My albums-folder being consolidated. Obviously, you have to re-create the hierarchy on the receiving computer and volume. That is, when you changed the path to the iTunes library, you cannot change to /Another volume/Music when you consolidate the My albums-root folder. Rather, you have to point it to /Another volume/Music/My albums.

After consolidating My albums, I duplicated this directory on the original volume and deleted the the original folder to be sure that the inode number changed. You should not need to do this, but I was so annoyed after working with this for a week so I felt »better safe than sorry». However, what you need to do is duplicate the My albums-folder and then delete the original folder in its new location to break the inode connection. The folder hierarchy must look something like this after consolidating the My albums-folder and preparing to consolidate the Demos-folder:

[old location]
Music
My albums (copy) [the probably not necessary step]
Demos [rename it back to its original name so iTunes' paths works]
Bootlegs (copy)
[new location]
Music My albums (copy) [to break the inodes]
Demos [an empty folder to which you point iTunes library prefs]

Now iTunes finds everything in the Demos-folder and has lost track of the My albums-folder (both on the original and the new location). iTunes also has lost track of the Bootlegs-folder in the original location. To distill this process:

  1. Duplicate all root level folders in your original location (to break inodes). Rename the one you will consolidate back to its original name (to make iTunes »soft links» to its files work).
  2. Create a folder in your Music folder on the new location with the same name as the folder you are consolidating (i.e. My albums)
  3. Change iTunes prefs to point to the folder you created in step 2.
  4. Consolidate library. If this was the last root folder you want to consolidate, break here and go to step 8.
  5. Duplicate the consolidated folders, both on the original and new location (to break inodes). Delete original folders.
  6. On the original location, rename the next folder you will consolidate to its original name (by removing » (copy)» at the end of the folder's name; this enables the soft links).
  7. Repeat from step 2 with all folders.
  8. You now have a hierarchy like this on the new location:
    Music
    My albums (copy)
    Demos (copy)
    Bootlegs
  9. Quit iTunes and remove » (copy)» from all folders names.

Start iTunes and see that all warnings about missing songs are gone. To be completely sure that the consolidation really worked, you can quit iTunes again and unmount the volume with the original Music folder on it, and then start iTunes again. To find any missing tracks, you use a script, e.g., List MIA:s which you can find on malcolmadams.com/itunes/

Caveats:

  1. My compilation directory was destroyed; now I have a lot of folders with only one or two songs in them. I would appreciate suggestions on how to fix this.
  2. I think this method is a PITA; really, there should be an easier way. Basically you only need to change the prefix in the search path in iTunes' library, something like replacing the string /Volumes/Old location/Music/ with /Volumes/New location/Music/ on every entry in the iTunes track database

Now I only miss one feature in iTunes -- improved intelligent playlists that lets you create playlists with the 25 most played songs minus the ten most played songs. This way your playlist would automatically compensate with new songs rather than today's situation where most played playlists just increse the tendency of a track being played frequently, which leads to a situation where you get bored of the music. Any takers?


This hint has been published at Mac OS X Hints. You are welcome to post in the thread there, I read it regularly and will do my best to answer any questions or comments.

Valid XHTML 1.0!

[an error occurred while processing this directive]