Jan 13, 2009

Though I use it’s not a perfect representation of my listening habits. Between the occasional server downtime, not uncommon in the Audioscrobbler days, I wanted to be able to get some accurate statistics about my music library. It’s easy to create smart playlists to find the number of songs you have of each genre or by each artist in your library, but much more interesting is to see what you actually listen to the most. There are a number of artist whom I only have a limited collection of, but enjoy quite a lot. DJ Miko being a great example - 10th by number of tracks, but a strong 3rd by playcount. I just can’t get enough of those Eurodance beats. Conversely, Scooter is a prolific producer, but a long way from my favorite artist.

Genre-wise, I’ve got a lot of trance, but apparently end up listening to Ska more. Is that really true? Well, it is by playcount, but I should probably to a listing based upon playcount times song length; Trance tracks tend to be lengthy, especially if you count the numerous DJ mixes I have. By this same token, I’d venture a guess that the average song length of my library, 5 minutes 13 seconds is on the longer end of the spectrum. Finally, the ratio of songs to artists is a quite reflection of whether a library is represented by an encyclopedic collection for each artist (high ratio) or a schizophrenic mix of singles (lower ratio). I have no idea what an absolute scale for this number is, but I’d love to hear results from others.

Also, my library has grown quite a bit:

Number of tracks: 10737
Total size: 85605.68 MB         Average size: 7.97 MB
Total time: 38d 23h 3m 0s       Average time: 5m13s
Ratio of songs/artists: 4.576726342711

Most popular artists, by number of tracks: 137 ATB 118 Scooter 116 blink-182 115 Armin van Buuren 111 Paul van Dyk

Most popular artists, by playcount: 1585 blink-182 1279 Goldfinger 873 DJ Miko & Mini Me 837 Less Than Jake 753 Big D and the Kids Table

Most popular genres, by number of tracks: 1627 Trance 1219 Dance 1073 Ska 628 Rock 583 Vocal Trance

Most popular genres, by playcount: 8448 Ska 6334 Dance 5328 Trance 2846 Punk 2723 Rock

It’s certainly been a while since I started this project and the module that I spun off of it has been around for a good while. I’ve compiled the script into a PAR that should run without needing Perl or any modules on any 64 bit Mac OS X machine. From a terminal:

chmod +x itunesstats
./itunesstats ~/Music/iTunes/iTunes\ Music\ Library.xml 5

If that doesn’t work for you, you can simply install Mac::iTunes::Library with CPAN; CPAN might require configuration but, except for mirror selection, the defaults will work:

$ sudo -H cpan -i Mac::iTunes::Library

With the module installed, you can download and run the example script.

Details on the code: The module allows you to parse the iTunes XML library which is generated by iTunes every time the library changes. iTunes itself uses a binary file to manage your music and the XML is only generated as a courtesy. Thus, my module can represent a library and the items within it in full, but I only have a parser for the XML and provide no way of emitting a new XML library. brian d foy has a module that is able to parse the binary iTunes - as long as it’s version 4.5. For the uninformed, we’re on iTunes 8 these days. Updating that module might be my next project.