[Pythonmac-SIG] appscript: selecting many songs in iTunes

Niko Matsakis niko at alum.mit.edu
Mon Jan 16 09:20:46 CET 2006

I have a program which identifies duplicates in iTunes and attempts  
to delete them automatically.  It seems to work like a charm, except  
for one problem: once I have identified the set of songs to delete, I  
have to go through them one-by-one and delete them.  So, if I have  
accumulated the database_IDs for a set of songs into a list  
'songdbids', I do something like:

	allsongs = app ('iTunes').sources['Library'].playlists 
	for songdbid in songdbids:
		allsongs.filter (its.database_ID == songdbid).get()[0].delete ()

This works fine when I test on small music collections, but when I  
try to run it across my full set of music it takes forever (as you  
might imagine).

Now, the number one rule of appscript performance which has been  
drilled into my head is to avoid AppleEvents like the plague.  To  
that end, it seems like what I want to do is something like:

		allsongs.filter (its.database_ID in songdbids]).delete ()

except I don't think that the 'in' operator works, and it looks like  
I'm missing a get() in there in any case.

Can anyone think of a better way to do this?  Perhaps I am on the  
wrong track altogether in working with database_IDs?  I can't select  
by album or artist, however, as that would delete both copies of the  
duplicated album (naturally).


More information about the Pythonmac-SIG mailing list