Merge iTunes Libraries

If you use iTunes on multiple computers, you’ve probably run into the problem of having several copies of the same song in different places and no good way to get one consolidated library of all your songs. The method described here doesn’t merge the iTunes xml file, but it will merge all of your song files to make sure you have one copy of each song. Once you have this consolidated directory, you’ll have to re-import all of your music into iTunes.

It is wise to make sure you have a backup before trying something like this just in case something goes wrong or you execute the command in the wrong directory. As far as I’m aware there isn’t anyway to lose data using this, but backups are always a good thing.

The tool we are going to use to merge directories is called rsync and it comes with OS X. There are versions available for Windows as well, but this tutorial is going to focus on OS X. Rsync is a tool that allows you to take a source and destination directory and make the destination directory contain all of the most recent changes from both directories merged together. In doing the merge the most recent file wins.

Rsync can work over network connections so you can synchronize multiple computers without manually copy files to one machine. However, to keep things simple for this tutorial we are going to assume that all of the iTunes directories you want to sync are on the same machine and that they are called iTunes and iTunes2. We want to make iTunes contain a copy of all of the files in iTunes and iTunes2 without duplicates.

Open up a terminal window and execute the following command:

rsync /Users/me/Music/iTunes2/ /Users/me/Music/iTunes

This will take everything from the first directory (iTunes2) and combine it with all the files in the second directory (iTunes). Notice the trailing slash after the first directory (iTunes2/). This trailing slash is very important. Without it rsync will create a new directory called iTunes2 inside of iTunes which isn’t what we want.

In this example iTunes and iTunes2 are directories that have the artist directories in them. For most users the actual directories will look something like this:

rsync /Users/me/Music/iTunes2/iTunes\ Music/ /Users/me/Music/iTunes/iTunes\ Music

Notice the backslash before the space in iTunes Music. It tells the command line to treat “iTunes Music” as one directory and not two separate arguments to rsync. If you want to run rsync without touching any of your original directories, you can run the command using a new empty directory as the second argument and run the command several times with every directory you want to combine. It would look something like this:

rsync /directory1/ /new_directory
rsync /directory2/ /new_directory
rsync /directory3/ /new_directory

This would combine everything from directory1, directory2 and directory3 into the directory called new_directory. It would only put the most recent copy of each file with no duplicates, so if directory1 and directory2 had some of the same files, only the most recent one would end up in new_directory.

Be Sociable, Share!

11 thoughts on “Merge iTunes Libraries

  1. Pingback: » Merge iTunes Libraries

  2. I have file son my iPod shuffle, but they were placed there with a different computer. I downloaded some sings from iTunes store and when I wanted to put them on my iPod, it said it would have to erase everything on it since I know had 2 music libraries.
    My problem is similar to the above, except that instead of 2 computers, I have an ipod and one computer.
    Thanks for any help.
    E. Noble

  3. You forgot to include the recursive call, if you leave that out Terminal will just skip the directory entirely. So instead, include a -r in your command:

    rsync -r /Users/me/Music/iTunes2/ /Users/me/Music/iTunes

  4. There’s one major issue with this plan – it would appear that doing an rsync and then reimporting all the files *loses all song ratings and playlists*. For some folks that isn’t a big deal, for me its a gigantic drawback. (Ratings more than playlists.) I’m going to see if I can come up with a method for pulling the ratings in from the previous libraries – if I can make one, I’ll post it here… Otherwise, this hint is a great idea with one big caveat.

  5. You advise is a life safer.

    One question… How do I identify a directory on another hard drive (not the harddrive with my Mac OS X)?

    Thank you. Thank you. Thank you, in advance.

  6. A new product has been released called TuneRanger that will synchronize and merge iTunes libraries on separate computers over a network. It does music, video and playlists and all changes appear in iTunes immediately. Versions for Mac and Windows are available making cross-platform iTunes library synchronizations possible.

    More info at http://www.acertant.com or http://www.tuneranger.com

  7. @Macslut

    See also the command line utility ‘touch’ paired with ‘xargs’. In the iTunes directory, for instance, you could try something like:

    find . -type f -print0 | xargs -0 touch

    Which would find all the files in the entire iTunes directory hierarchy, print them out into a list, then pipe that to xargs which would run that list as one motherload of arguments in touch. find finds stuff, | is a pipe, xargs runs lists as arguments of any utility, and touch updates files’ modification times.

  8. hi,
    i have a question about merging the libraries.
    am i correct that actually this is only about the music files?
    what will happen with the artwork for instance?
    any suggestions appreciated, i’m trying to merge my notebooks lib and my works lib together on a nas disk, and have noticed that swapping libraries using the apple start option already seemed to create loss in the artwork i’ve collected so far.

  9. Thanks for this — after moving a number of tracks to my other computer temporarily but keeping them referenced in the iTunes library, this tip saved me HOURS of manual reimporting songs where I had downloaded new music by the same artists!

  10. Pingback: Merging iTunes Libraries « I’m just a blog

Leave a Reply