Last active
July 24, 2017 17:58
-
-
Save bradhowes/f187889861c9fd8d05340169857b0bde to your computer and use it in GitHub Desktop.
Locate albums in iTunes with a low aggregate play count (Python 2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import plistlib, sys | |
from pprint import pprint | |
delimiter = '~' | |
def scan(srcRoot, playLimit): | |
albumMap = {} | |
for trackId, attributes in srcRoot['Tracks'].iteritems(): | |
albumName = attributes.get('Album') | |
artistName = attributes.get('Album Artist') | |
if albumName is None or artistName is None: | |
continue | |
itemKey = (albumName, artistName) | |
playCount = attributes.get('Play Count', 0) | |
albumMap[itemKey] = albumMap.get(itemKey, 0) + playCount | |
for key, value in albumMap.iteritems(): | |
if value <= playLimit: | |
print key[0] + delimiter + key[1] + delimiter + str(value) | |
def run(srcPath, playLimit): | |
print '-- loading', srcPath | |
srcRoot = plistlib.readPlist(srcPath) | |
scan(srcRoot, playLimit) | |
if __name__ == '__main__': | |
if len(sys.argv) != 3: | |
print "python noPlay.py LIBRARY_PATH PLAY_LIMIT" | |
print " LIBRARY_PATH: path to iTunes XML file" | |
print " PLAY_LIMIT: max number of track plays to show" | |
sys.exit(1) | |
run(sys.argv[1], int(sys.argv[2])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use: