Tuesday, April 7, 2009

Files multiple times in iTunes

I ran into the problem that i had imported big parts of my mp3 collection into iTunes more than once. Actually i started importing them a couple of times and for some reason i cancelled the import. I ended up with many of my songs multiple times in my library folder.

iTunes has the ability to show me the duplicate files, but they were too many to manually delete them. So I wrote a little python script:

import os
itunes = os.walk("/Users/" + os.getlogin().capitalize() + "/Music/iTunes")
for (path, subs, files) in itunes:
for file in files:
for i in range(0,10):
duplicatefilename = file[:-4] + " " + str(i) + file[-4:]
if duplicatefilename in files:
os.remove(os.path.join(path, c))
print (os.path.join(path, c))


You can put that code in a file, say "removeduplicates.py" and then run it by typing

python removeduplicates.py

It'll take a while depending on your itunes library size, but it'll get them all...

After that I had lots of dead tracks in my library, as the files were deleted, but the itunes index not updated. looking around a little, i found a solution

what i'm still very unhappy about is that ican't use my old .m3u files. :(

No comments: