Skip to content. Skip to navigation

Myriadicity Dot

Views

I'm a big fan of iTunes playlists, and want to be able to easily synchronize my main ones to my G1 android phone. I developed Mac OS python script to scratch that itch, enabling me to replace my old iPod with my G1 (plus a 16GB micro SD card). The script ensures accurate copies of a selected iTunes playlist, all its contained playlists, and all the music tracks contained on those playlists in a selected target directory on my Mac computer.

The script runs only on MacOS with operational iTunes and requires python with appscript installed.

I developed and have been using the script since about October, 2009. I synchronize a collection of around 90 playlists, which includes around 1900 MP3 tracks, quickly and cleanly. I hope the script might be useful to you. It is free and open source (under a dual GPL and Apache license). If you're running Mac OS X and use iTunes, please give it a try and let me know what you think!

playlistsync.py

Features

  • Only those items necessary to rectify differences with the files already in the target hierarchy are copied.

  • The target directory is also purged of playlists, track files, and directories which do not correspond to any elements within the subject playlist's hierarchy. (Other files and directories are left undisturbed.)

  • The destination playlists are named for their originating playlists location in the containment hierarchy, eg "Rock_Alt_NewWave" for the "NewWave" playlist in the "Alt" playlist folder that's contained in the "Rock" playlist folder.

  • Like the playlist folders in iTunes, the playlist files corresponding to each iTunes playlist folder include the tracks of all the directly and indirectly contained subfolders and playlists.

  • Simplistic shuffle-play schemes (like that of Android's default music player) always start with a playlist's first track, and shuffle from there. This script provides a workaround, setting the first track to a dummy "stub track", one that is brief and silent. I use a track that consists of just 1 second of silence.

    To use this feature, include such a track in your iTunes library and assign the track's name to the variable USE_STUB_TRACK (default = '00 Stub Track'). You need not explicitly include the stub track on any of your iTunes playlists - it will be included at the top of the destination playlists automatically.

  • Failsafe - to avoid unintended deletion of music files in mistaken target directories, the target directory must contain a file with the name specified by TARGET_DIRECTORY_FAILSAFE_FILE. The user is prompted for creation of the failsafe file if absent, eg the first time the script is run.

Configuration and Operation

Follow the python appscript instructions to install appscript in the python you'll be using to run the script.

Configure the script by setting variable names in the script code and/or using command-line options, overriding the persistent configuration variables. See the script code, below the "Configuration Below" line, for the user-configurable variables, with explanations. Invoke with '--help' to see the available options.

The synchronization target directory must exist and be writable.

To avoid unintended deletion of music files in mistaken target directories, the target directory must contain a file with the name specified by TARGET_DIRECTORY_FAILSAFE_FILE. You will be prompted for creation of the failsafe file if absent, eg the first time you the script targets that directory. You can tell the script to create the failsafe file when necessary, without prompting, by setting ALWAYS_CREATE_FAILSAFE True or passing in "-c" / "--create-failsafe".

Invoke by applying the appscript-equipped python on playlistsync.py, specifying the target directory with the '-d' option if you haven't configured the TARGET_DIRECTORY_PATH script setting:

python playlistsync.py -d /Volumes/G1_USD/Music/synchronized

Known Problems

My system sometimes hits an appscript timeout bug, where appscript hangs after a certain number of interactions, and after sixty seconds of being stuck raises a timeout exception. The script works around this problem by catching the exception and restarting the sync process - quickly skipping over the already accomplished work and resuming where it left off. If the timeout returns with too little intervening progress, the script quits. This rarely happens, but if it does you may have to restart your machine to clear it. The problem rarely happens to me under Snow Leopard, and i've only once had to restart my machine.

(You can run the script in a dummy mode to elicit a possibly related timeout every time, always at around 65,300 (around 2**16) interactions and often a bit before - varying between 57000 and 58000 for me - by invoking it with '--timeout-test'. It will print progress counts every 1000 interactions, stopping when the exception is hit or if it runs cleanly past 2**16 interactions, reporting the final disposition either way.)




subject:
  ( 9 subscribers )


Sections
Personal tools
Powered by Plone, the Open Source Content Management System