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