Accessing iTunes with Python via the Windows SDK

Tony Meyer tony.meyer at gmail.com
Thu May 24 01:17:01 EDT 2007


On May 24, 4:23 pm, Denrael <lear... at gmail.com> wrote:
> I've been playing with the iTunes sdk on windows, and have come across
> a strange problem.  With the following code:
>
> import win32com.client
> iTunes = win32com.client.gencache.EnsureDispatch("iTunes.Application")
> curr = iTunes.CurrentTrack
> name = curr.Name
> skipped = curr.SkippedCount
[...]
> I get an error indicating that SkippedCount isn't a valid attribute:
[...]

The object you get back from iTunes.CurrentTrack (the traceback shows
this) is an IITTrack.  If you check the iTunes SDK, you'll see that
IITTrack objects don't have a "SkippedCount" attribute -
IITFileOrCDTrack objects do (from memory, this excludes things like
radio links).  You need to conver the IITrack object to a
IITFileOrCDTrack object (assuming that it is one); you can do this
with win32com.client.CastTo, as follows:

"""
import win32com.client
iTunes = win32com.client.gencache.EnsureDispatch("iTunes.Application")
curr = win32com.client.CastTo(iTunes.CurrentTrack, "IITFileOrCDTrack")
name = curr.Name
skipped = curr.SkippedCount
skipdate = curr.SkippedDate
print name
print skipped
print skipdate
"""

Cheers,
Tony




More information about the Python-list mailing list