views:

273

answers:

1

Hi. I have been messing around with iTunes COM from python.

However, I haven't been able to access the Lyrics of any track.

I have been using python for this. Here is the code:

>>> import win32com.client
>>> itunes = win32com.client.Dispatch("iTunes.Application")
>>> lib = itunes.LibraryPlaylist
>>> tracks = lib.Tracks
>>> tracks
<win32com.gen_py.iTunes 1.12 Type Library.IITTrackCollection instance at 0x16726176>
>>> tracks[1]
<win32com.gen_py.iTunes 1.12 Type Library.IITTrack instance at 0x16746256>
>>> tracks[1].Lyrics
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "D:\Programas\Python26\lib\site-packages\win32com\client\__init__.py", line 462, in __getattr__
    raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr))
AttributeError: '<win32com.gen_py.iTunes 1.12 Type Library.IITTrack instance at 0x16780824>' object has no attribute 'Lyrics'

tracks[1] has no attribute 'Lyrics' because it is of type 'IITTrack'. Only 'IITFileOrCDTrack', which is a sub-type of 'IITTrack' has this attribute. My question is how to access the 'IITFileOrCDTrack's? Or how to convert a 'IITTrack' to a 'IITFileOrCDTrack'?

Any help on this is greatly appreciated. Thanks.

P.S: Info on how to download documentation of iTunes COM interface here.

A: 

Try to convert it like this (not tested):

track_converted = win32com.client.CastTo(tracks[1], "IITFileOrCDTrack")
ChristopheD