If this list is the wrong place, I apologize; just let
me know and I'll ask in the right place. Otherwise:
Now that I can use appscript with Python 2.4 on my
Intel box, I've been going back over some of my
iTunes-controlling scripts, and I've run into two
problems and one stupid question.
First, whenever I try to get a date through appscript,
at least from iTunes, I get a "CommandError: long int
too large to convert to int". I'll give the full
traceback below. So that my script that should list
the last N tracks played in iTunes crashes instead.
Second, whenever I ask for a missing value, the result
is something like aem.AEType('gnsm'). I have a bunch
of scripts that just do things like "if artist:" and
now they have to do things like "if isinstance(artist,
unicode):" instead. This used to work (on a Mac with
ancient versions of appscript and MacPython).
Finally, the stupid question: Is there any easy way to
convert a list of references into a single reference
to the list? (To allow a single IPC call instead of
one per reference.)
In my iTunes scripts, I do this by generating a big
filter:
# slow version
ids = [281, 1099, 731, 414, 238, ...]
tracks = [library.file_tracks.ID(id) for id in ids]
names = [track.name() for track in tracks]
# fast version
dids = [168, 142, 57, 39, 277, ...]
idfilters = [(its.database_ID == did) for did in
dids]
idfilter = idfilters[0]
for f in idfilters[1:]:
idfilter = idfilter.OR(f)
trackrefs = library.file_tracks.filter(idfilter)
names = trackrefs.name()
Is there an easier way to get all the names in a
single IPC call? (Also, is there a way I can filter on
the ID instead of having the fetch and keep around the
database_ID for everything?)
Here's what I'm doing this for: My other Mac has the
whole library on shuffle, and I hear something and
think, "Wow, what was that song?" So I do this:
$ ssh emac
$ iwhat `ilast 3`
468: Add N to (X) - Large Number
693: ADULT. - Hairing Impaired
241: T. Raumschmiere - R.Ror
$ iwhat -a 693
693: ADULT. - Hairing Impaired (D.U.M.E. 5/6, 2005)
02:36 0/100
$ iplaylist "D.U.M.E." `ibatch 693`
$ iplay "D.U.M.E."
$ irate 90
...
>From across the room, I figured out which of the
recent songs was the one I wanted, made a playlist of
all the songs in the same import batch, started
playing it, rated the current track (the first one)
4-1/2 stars, etc. (I remembered that I bought
D.U.M.E., ripped it, then had to go out and never
listened to it....)
The ilast and ibatch scripts need dates, the iwhat
script needs to understand missing values, and a bunch
of the scripts either return a list of IDs (ilast,
ibatch, iadd, isearch, ...) or take a list of IDs
(iwhat, iplaylist, irate, ...). Hence the questions.
Finally, here's the traceback I promised:
$ ibatch 142 168
Traceback (most recent call last):
File "./icontrol-server", line 117, in ?
dates = trackrefs.played_date()
File
"/Library/Python/2.3/site-packages/appscript/specifier.py",
line 356, in __call__
return self.get(*args, **kargs)
File
"/Library/Python/2.3/site-packages/appscript/specifier.py",
line 204, in __call__
raise CommandError(self, (args, kargs), e)
appscript.specifier.CommandError: long int too large
to convert to int
Failed command:
app(u'/Applications/iTunes.app').library_playlists[1].file_tracks.filter(((its.database_ID
== 168).OR(its.database_ID == 142))).played_date.get()
_______________________________________________
Pythonmac-SIG maillist - [email protected]
http://mail.python.org/mailman/listinfo/pythonmac-sig