[Pythonmac-SIG] appscript: selecting many songs in iTunes
Niko Matsakis
niko at alum.mit.edu
Tue Jan 17 14:24:42 CET 2006
Shoot, fired that last e-mail off a bit early. Please ignore in
favor of this more complete version.
> Depends what you're trying to get. iTunes scripting interface is
> pretty extensive, but a lot of the implementation is rather crude
> and many commands won't work on more than one object at a time. So
> the above might work as-is, but it probably won't, in which case
> you need to get a list of track references and tell iTunes to
> delete each individually:
Okay, so this error is probably iTunes' fault?
> appscript.specifier.CommandError: Application Error -10014: Handler
> only handles single objects.
> Failed command: app(u'/Applications/iTunes.app').sources
> ['Library'].playlists['Library'].tracks.filter(its.database_ID.isin
> ([7253, 7255, 7257, 7259, 7261, 7263, 7265, 7267, 7269, 7271, 7273,
> 7275, 7277])).get()
As you can see, I am just trying to fetch a list of references in
this case, not delete them in one step. Here is my python code:
handlers = _get_tracks().filter (its.database_ID.isin (idlist)).get ()
for handle in handlers:
handle.delete ()
where _get_tracks() is:
def _get_tracks ():
return app ('iTunes').sources['Library'].playlists['Library'].tracks
Is there something wrong with what I am doing? If I modify
its.database_ID.isin() to be its.database_ID == id, and iterate
through idlist, it works fine (but, as we know, slow); this makes me
think it is correct.
If this *is* just a limitation in iTunes, I have to admit I'm a bit
of a loss as to how to proceed. I guess one option is just to purge
the files themselves, and then use one of these scripts which purges
all tracks that have no corresponding file. Well, that or clear the
iTunes library entirely and re-build based on the files that still
exist. While these two solutions would work for me, they are clearly
hacks and I was hoping to roll this into something useful to a wider
audience some day.
thanks again,
Niko
More information about the Pythonmac-SIG
mailing list