Transfer ratings from one iTunes Mac to another

I’ve consolidated all of my media onto my new Mac Mini, but didn’t really think some things through when I first did it. For instance, I put all of my video data in before transferring my music across. I’ve still kept a copy of my music on the laptop, for what it’s worth, but because I just copied files, then I lost all of my rating data.

I looked at a couple of solutions for transferring the ratings, the most promising was a semi-manual method of creating smart playlists, one for each rating.

That was too old-tech for me, so I came up with a solution that uses Remote Apple Events. Now, to make the code easier, I’m using python and appscript, so make sure you have both of those installed.

 1     #! /usr/bin/python  
 2     
 3     import appscript  
 4     
 5     # Set up the two iTunes libraries.  
 6     local = appscript.app('itunes')  
 7     
 8     # You'll need to replace jens.local with your remote machine's name  
 9     remote = appscript.app(url='eppc://jens.local/itunes')  
10     
11     local.lib = local.playlists()[0].tracks()  
12     remote.lib = remote.playlists()[0].tracks()  
13     
14     # Create a dictionary with all local track names/artists/albums  
15     library = {}  
16     
17     for each in local.lib:  
18         key = each.name()+":"+each.artist()+":"+each.album()  
19         library[key] = each  
20     
21     # Iterate over every remote track.  
22     # If it is in the local library, take the local rating and  
23     #    apply that to the remote track.  
24     for each in remote.lib:  
25         key = each.name()+":"+each.artist()+":"+each.album()  
26         print key,  
27         if library.has_key(key):  
28             each.rating.set(library[key].rating())  
29             print "rated."  
30         else:  
31             print "doesn't exist in local library"  

That’s it. I’ve used this to transfer all of my ratings from local to remote iTunes. Granted, there is no check to see if I’ve got all of the local tracks on the remote machine - but that is mainly because I don’t have my Podcast library on the remote machine, and I hope (know?) I have all of the music, and that’s the stuff I care about.

Here’s a screenshot from my remote library.