Syncing iTunes Playlists

This script reads your iTunes library and copies specified playlists to any destination folder. It also keeps track of any files that may have been updated since the last sync and copies those across too (e.g. album art updates).

Download the script here
Source code

Pre-requisites

This script will probably only work on Mac OS X. I think it would need some changes to work on Windows which I'm not interested in doing. You will also need Perl installed and also Math::Round and File::Copy;. To install these:

cpan Math::Round File::Copy

Installing the script

Stick the file in some appropriate directory, such as /usr/local/bin and give it appropriate permissions:

sudo cp async /usr/local/bin
sudo chmod +x /usr/local/bin/async

The script should be installed. You will now need to configure it.

Configuration

There are two ways to configure the script. The first is to simply edit it with a text editor and replace various variables. The other is to create a configuration file. We'll assume you wish to do the latter.

Create the file ~/.asyncrc and put the following inside it, replacing as needed:

# Async config file
# Your iTunes folder, typically /users/HOME/music/iTunes/
itunes=/users/REPLACE_ME/music/itunes
# Where you want your music copied to (e.g. your USB or Android device)
dest=/volumes/sd card/music
# A list of playlists you want copied. For all your music, then add playlist=library
playlist=bob dylan
playlist=hard
playlist=pink floyd
playlist=favourites
playlist=sync

Save this file and then run async (simply type async at the command line).

Mulitple Configuration Files

You can create multiple configuration files like the above for various needs (e.g. one to sync a usb thumb drive for your car, another for your phone and so on). To use them, simply pass the configuration file as an argument. For example:

async ~/.carsync

Advanced Options

The configuration file accepts the following options:

itunes

The itunes argument specifies where the "iTunes Music Library.xml" file is located. This filename can be changed with itunes_xml (below).

itunes=/users/matt/music/itunes

dest

The destination directory for your files.

dest=/volumes/sd card/music

itunes_xml

The filename for your iTunes XML library. Default is iTunes Music Library.xml

itunes_xml=iTunes Music Library.xml

playlist

Playlist to sync. Can have multiple entries. Use 'library' to sync entire iTunes library.

playlist=bob dylan
playlist=sync

info

Set to 1 to enable information output (default = 1)

info=1

verbose

Set to 1 to enable verbose output (default = 0)

verbose=1

debug

Set to 1 to enable debug output (default = 0)

debug=0

no_copy

Set to 1 to disable copying for debug purposes (default = 0).

no_copy=0

no_delete

Set to 1 to disable file/folder deletion for debug purposes (default = 0).

no_delete=0

db_dir

Directory to store the local changes database (default = ~/.async)

db_dir=~/.async

db_file

File to store the local changes database in (default = autogenerated)

db_file=carsync

Troubleshooting

The most common problem is going to be the Perl directory. To fix this, type:

which perl

This should give you a directory - e.g. /usr/bin/perl - edit the async file to put it on the top line, prefixed with a shebang. For example:

#!/usr/bin/perl

This script almost certainly won't work on Windows and probably never will. Sorry.