Building a log of songs played in iTunes over time

Recently I decided I wanted to perform a statistical analysis of all the music I've ever played in iTunes. This is non-trivial, as iTunes only stores the date and time each song was played last and does not keep any log showing previous plays.

With several copies of my iTunes library file, I can reconstruct the overall history. Luckily, I am using Time Machine and can therefore retrieve snapshots of the library. This is enough to reconstruct the history going back over a year.

The only problem is that Time Machine does not back up the .xml files, only the proprietary .itl files used by iTunes natively. This means that I must perform all the following steps:

  1. retrive historical iTunes Library.itl files
  2. convert each .itl file into the corresponding .xml file
  3. parse each .xml file and build a log of songs played based on the last played parameter for each song
    1. fill in any blanks with fuzzy data (for instance, if a song has been played twice since the previously-determined date, make a guess as to when the last-1 listening may have occurred)

The full description of each step is detailed in the pages that follow.