Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Verify if all songs in the iTunes Library actually exists on disk
#Tool to valid all songs in iTunes Library
import plistlib
import urllib
import os
import json
import sys
from os.path import expanduser
iTunesTracks=plistlib.readPlist(expanduser("~")+"/Music/iTunes/iTunes Music Library.xml")["Tracks"]
InvalidItemList=list()
for key in iTunesTracks.keys():
item=iTunesTracks[key]
for uselesskey in ["Date Modified","Date Added","Play Date UTC","Skip Date"]:
if item.has_key(uselesskey):
del item[uselesskey]
try:
FileLocation=item["Location"] #RawLocation
except:
InvalidItemList.append(item)#We don't have the path to the actual file in the Library somehow. Assume it's lost
next
FileLocation=urllib.unquote(FileLocation).replace("file://","")
if (os.path.isfile(FileLocation)==False):
InvalidItemList.append(item)
f=open(expanduser("~")+"/Desktop/LostSongs.json","w")
f.write(json.dumps(InvalidItemList))
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.