#!/usr/bin/env python

diff_playlists.py

Copyright © 2008 Dave Bayer. Subject to a BSD-style license.


Usage:

diff_playlists.py xmlfile1 xmlfile2 outfile1 outfile2

Compares each playlist in xmlfile1 to the corresponding playlist in xmlfile2, writing tracks found only in xmlfile1 and xmlfile2 to outfile1 and outfile2, respectively. Playlists found only in xmlfile2 are not considered.

iTunes is capable of importing a playlist generated by a different use from a physically distinct set of tracks. However, it fails to report which tracks it could not find.

This script need not reside on the machine performing the actual iTunes import. It can be used later to analyze what happened, on a different machine that has Python and appscript installed. The output can then be used to manually repair the playlists in question.

This Python script is part of the iTunes project.


Import iTunes module:

from iTunes import *

Get command line arguments xml1, xml2:

xmlfile1, xmlfile2 = get_args(4, 'xmlfile1 xmlfile2 outfile1 outfile2')[:2]

Open remaining command line arguments as the unicode files out1, out2:

out1, out2 = open_args(4, '', start=3)

Diff the playlists:

diff_playlists(xmlfile1, xmlfile2, out1, out2)