iTunes win32com Python - AddTrack not working
Question: I've been using the following code to try and create a new playlist in iTunes
and a song from the main library - its example code i've found but i keep
getting the following error when it runs. I've had a look through the iTunes
COM interface documentation and it seems that AddTrack is only available under
IITLibraryPlaylist but all of the example code Ive found is as below. Can
anyone help>

Error: AttributeError: win32com.ge_py.iTunes 1.13 Type Library.IITPlaylist
instance at 0x34035192 object has no attribute 'AddTrack'

Python Code:

    
    
    import win32com.client
    
    itunes = win32com.client.gencache.EnsureDispatch ("iTunes.Application")
    
    mainLibrary = itunes.LibraryPlaylist
    tracks = mainLibrary.Tracks
    
    playlist = itunes.CreatePlaylist("Sonic Jams")
    song = tracks.ItemByName('Teen Age Riot')
    playlist.AddTrack(song)
    


Answer: i managed to get it using this code if anyone else needs it.

    
    
    playlist = win32com.client.CastTo(itunes.CreatePlaylist("New List"), 'IITLibraryPlaylist')    
    song = tracks.ItemByName('Silver Rocket')
    playlist.AddTrack(song)
    

