How long have you iTunes-d?

I like the bit that appears at the bottom of iTunes, telling you how much music you have in your collection (or in the current playlist). iTunes Library Size I thought it might be fun to see how much music I had listened to. As it turns out: 5883 songs, 17:13:27:05 total time. Here is the script I wrote to find it out.

 1     #! /usr/bin/env python
 2     
 3     import Foundation
 4     import os
 5     
 6     library =  os.path.expanduser('~/Music/iTunes/iTunes Music Library.xml')
 7     
 8     db = Foundation.NSDictionary.dictionaryWithContentsOfFile_(library)
 9     tracks = db[u'Tracks'].itervalues()
10     
11     timecount = 0
12     playcount = 0
13     
14     for track in tracks:
15         try:
16             timecount = timecount + track[u'Play Count'] * track[u'Total Time']/1000
17             playcount = playcount + track[u'Play Count']
18         except KeyError:
19             pass
20     
21     days, timecount = timecount / (60 * 60 * 24), timecount % (60 * 60 * 24)
22     hours, timecount = timecount / (60 * 60), timecount % (60 * 60)
23     minutes, seconds = timecount / 60, timecount % 60
24     
25     print '%i songs, %i:%02i:%02i:%02i total time' % (playcount, days, hours, minutes, seconds)

Daring Fireball: About the Footnotes

Daring Fireball: About the Footnotes John Gruber talks about the use of footnotes in blog posts. What strikes me as a good way to do stuff is to have a multi-line abbreviation-style tag, that floats over the text where the pointer is when hovering.1