Skip to content

Instantly share code, notes, and snippets.

@bradhowes
Last active July 24, 2017 17:58
Show Gist options
  • Save bradhowes/f187889861c9fd8d05340169857b0bde to your computer and use it in GitHub Desktop.
Save bradhowes/f187889861c9fd8d05340169857b0bde to your computer and use it in GitHub Desktop.
Locate albums in iTunes with a low aggregate play count (Python 2)
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]))
@bradhowes
Copy link
Author

To use:

python2 noPlay.py ~/Music/iTunes/iTunes\ Library.xml 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment