Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.4: Sync iTunes via rsync, python, and Automator Apps
OK, this is my first hint, but I figured I should share.

This is by no means an elegant solution, but it works for me. I'm using a combination of rsync, python, and Automator to sync my iTunes libraries between machines. Here's how...
  1. Get the files from one computer to the other. I use rsync for this. Additionally, you will need to have Personal File Sharing enabled on the destination computer:
    rsync -avzu /local/music/folder 
    username@destination_computer.local:/dest/music/folder
    Add an n to the options the first time you try, as it will just do a dry run and you can see if it's going to work. Now you have all the files on the destination computer, but iTunes still doesn't know anything about them.
  2. The following is to be done on the destination computer. Download my syncTunes.py python script (original host | macosxhints mirror). We will actually be using Automator to call this script. The script compares all of the actual music files in the directory tree with the files that are in the iTunes library (make sure you quit iTunes first). It then prints out a list of all of the mismatched files (there will be more than you think, but don't worry about it).
  3. Download the librarySync automator workflow (original host | macosxhints mirror). You will have to modify the arguments in the first block of the workflow for your particular folder arrangement. Once the paths are set, run the workflow.
In the future, it is only necessary to do steps one and three. It's not beautiful, but it gets the job done for me.

[robg adds: I haven't tested this one.]
    •    
  • Currently 2.00 / 5
  You rated: 1 / 5 (5 votes cast)
 
[30,281 views]  

10.4: Sync iTunes via rsync, python, and Automator | 10 comments | Create New Account
Click here to return to the '10.4: Sync iTunes via rsync, python, and Automator' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Sync iTunes via rsync, python, and Automator
Authored by: ebroder on Mar 02, '07 10:09:09AM

I've been using Unison for a while. It's the same software that MyDreamApp's Portal is going to be based on. It syncs over SSH, resolves conflicts in both directions, and is kind of cool.

The other thing I did is that I setup multiple sync profiles so that I could sync Music, Docs, Movies, etc independently. This also meant that I could keep my docs in sync with a Windows machine, because on Windows I set the My Docs profile to ignore My Music, etc. It's also relatively easily cron-able, you just need a little extra magic to keep multiple instances from running at the same time. Here's the script I wroteup (it takes the profile name to sync as a single argument):


#!/bin/bash

PATH=/sbin:$PATH

if [ ! -f "/Users/evan/Library/Application Support/Unison/$1.prf" ]; then
	echo "Error: please specify valid profile"
	exit 1
fi
if [ -f "/tmp/sync_$1" ]; then
	exit 2
fi

IPADDRESS=`ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'`
if [ "${IPADDRESS:0:3}" != "18." ]; then
	exit 3
fi

touch /tmp/sync_$1
unison -batch $1
rm /tmp/sync_$1
(The script also only syncs when I'm on my school's network)

[ Reply to This | # ]
10.4: Sync iTunes via rsync, python, and Automator
Authored by: sdrubbins on Mar 02, '07 10:28:15AM

Very good idea... though personally I'd just use Applescript rather than Automator.

Unison or rsync, there's not much difference; the main benefit in the original post is the python script that allows iTunes to see and reflect any changes resulting from the sync.

Ideally, and without too much work, you want to wrap all of this up in an Applescript (which can call rsync, python scripts and Automator workflows), adding in a

try
tell application "itunes" to quit
end try

...in the beginning and a

tell application "itunes" to activate

...in the end. Then save it as an application and use it every time you want to launch iTunes. You can run a variation of it on both local and remote machines, and both copies of iTunes will be up-to-date every time you use them.

It might take a little work to separate syncing different media (e.g. one of my copies of iTunes has a bunch of videos, the other doesn't, but I want the music to always be the same for both) but it's totally doable.



[ Reply to This | # ]
10.4: Sync iTunes via rsync, python, and Automator
Authored by: neuralstatic on Mar 02, '07 01:07:06PM

is there a big value for you to have 2 copies of your entire library?
i have my shared vids and music on a 500gb share, and then just update the podcasts and prefs.

when you have a big library, you definitely don't want to have to build your itunes list of tracks more than you have to, so i do a DSW auto launch of a sync script.



[ Reply to This | # ]
10.4: Sync iTunes via rsync, python, and Automator
Authored by: tirerim on Mar 05, '07 12:36:02PM

There is when one of the machines in question is a laptop, and you don't want to be carrying around an extra drive.



[ Reply to This | # ]
10.4: Sync iTunes via rsync, python, and Automator
Authored by: berndtj on Mar 06, '07 06:29:34PM

I agree that it most likely could all be an applescript. Sadly, I know nothing about applescript.

It could also become 1 automator action by adding the rsync stuff in. It would be interesting to use remote apple events to do this on the remote machine. Currently I'm VNC'ing in to run the automator script.

The reason that I chose automator, is the built in add files to iTunes playlist action. As everyone knows, just syncing the files, does nothing for your library.



[ Reply to This | # ]
10.4: Sync iTunes via rsync, python, and Automator
Authored by: extra88 on Mar 05, '07 10:30:16AM

First, don't use the -z switch for rsync for this. -z is "compress file data" but your files are almost all compressed (unless you have a lot AIFFs or something) so you're just wasting CPU cycles and time and possibly increasing the amount of data transferred.

If you keep your music within the default Music folder in your home directory (~/Music/), you don't need to do all the Automator stuff on receiving end, with one important caveat. I just make sure iTunes isn't running on the destination and sync the whole thing: rsync -a --delete-after /Users/USERNAME/Music/iTunes/ OTHERMAC.local:/Users/USERNAME/Music/iTunes/

The important caveat is I've found that my information about what podcasts I've already deleted is not preserved so the destination computer will re-download them and/or re-list old podcasts. I pretty much do my syncs one way and don't use the destination computer for podcast listening so I live with it. Note that my rsync example includes --delete-after which deletes any files from the destination that do not exist on the source (after it finishes transferring new data). If you don't have a delete switch in there (or use one occasionally) you can end up with deleted files coming back or redundant files in the case of files or folders getting renamed.

[ Reply to This | # ]

10.4: Sync iTunes via rsync, python, and Automator
Authored by: ADent on Mar 09, '07 06:11:37PM
When I run this I get

 File "/Users/test/Desktop/iTunesAutomation/syncTunesCopy.py", line 54, in getLibrary
    library.add((int(size), file.strip()))
ValueError: invalid literal for int(): 


[ Reply to This | # ]
10.4: Sync iTunes via rsync, python, and Automator
Authored by: luhmann on Mar 10, '07 06:06:24PM

"You will have to modify the arguments in the first block of the workflow for your particular folder arrangement."

Could you be a little more specific about this?

There are four values that need to be set:

python [PATH TO]/syncTunes.py

That's easy, its the path to syncTunes, but what are the other paths supposed to be? Root directory of you music folder, or your iTunes library folder? Or does this assume that they are in the same place?

--rootdir=
--library=
--folder=



[ Reply to This | # ]
10.4: Sync iTunes via rsync, python, and Automator
Authored by: gleatherman on Mar 24, '07 12:50:10PM

Yes more detail here would be great. This script is exactly what I've been needing to keep three different machines updated to new songs all on one large network drive. I'd love to be able to test it out!

thanks



[ Reply to This | # ]
10.4: Sync iTunes via rsync, python, and Automator
Authored by: luhmann on Mar 10, '07 06:20:40PM
Has anyone tried SuperSync?

http://www.supersync.com/

[ Reply to This | # ]