iTunes Library Checker 2.0

I’ve rewritten most of iTunes Library Checker to use some neater import code, it should also be a bit faster. Not quite complete yet, but close to the previous functionality.

 1     #! /usr/bin/env python
 3     import Foundation
 4     import os
 5     import struct
 7     library =  os.path.expanduser('~/Music/iTunes/iTunes Music Library.xml')
 8     db = Foundation.NSDictionary.dictionaryWithContentsOfFile_(library)
 9     libpath = Foundation.NSURL.URLWithString_(db[u'Music Folder']).path()
11     tracks = db[u'Tracks'].itervalues()
13     findstr = "find '"+libpath+"' -type f -not -name .aacgained -not -name ._* -not -name .DS_Store | sort"
14     treedata = os.popen(findstr).readlines()
16     missing = []
17     other = []
18     missing_files = []
19     other_files = []
20     surplus = treedata[:]
22     for track in tracks:
23         location = Foundation.NSURL.URLWithString_(track[u'Location']).path()
24         if not os.path.exists(location):
25             missing.append(track)
26             missing_files.append(str(location))
27         else:
28             try:
29                 surplus.remove(str(location)+'\n')
30             except ValueError:
31                 other.append(track)
32                 other_files.append(str(location))
34     missing_files.sort()
35     other_files.sort()
36     surplus.sort()
38     open('surplus.txt','w').writelines(surplus)
39     open('missing.txt','w').writelines(missing_files)
40     open('other.txt','w').writelines(other_files)

Simpler iTunes Library Checker

I posted some code exactly a month ago, then I find this. I will rewrite the code so it is simpler, using the MacOS hooks that come with PyObjC.

Deeper iTunes Data

I came across an interesting question today: Why doesn’t iTunes store all of the data about each time a song is played? And also, how much of the song was played? It should be easy to write a daemon that monitors iTunes, and writes this data to a database. This database can then be cross-referenced against the iTunes database for a comprehensive breakdown of when songs are played. You can then find all of the songs that you listen to at a certain time of day, or season, and so on. You can also have a ‘how-often-played’, but cross referencing the Date Added attribute with the Play Count and so on. I’ve already started to write this program, but it will likely be MacOS X only.

How Accurate is the iTunes Counter?

I got a comment to a post that had nothing to do with iTunes. Whilst it wasn’t a particularly helpful or nice comment, I thought maybe I can answer the question I think he’s asking. (Unless he’s talking about the iTunes Music Store counter that shows how many songs have been bought for the latest contest…). Wach time you finish playing a song, the Play Count field is incremented, and the Last Played date is updated. If you skip a song before listening to the entire track, neither of these are updated. There are some scripts around for MacOS AppleScript that will update a Play Count and Last Played if you listen to more than a certain amount of a track. I could also add the same feature to iTunes Rater. But I don’t really use Play Count and Last Played that often, anyway.