Python code not working to delete an existing playlist

Hi there. I have been using VbScripts with itunes since circa 2010, and they always worked to perfection.

However, since Vbscript is outdated and Python is the new coqueluch in town (everybody is catching it), I decided to convert my programs into it.


However, I'm totally puzzled why the code is not working to delete a playlist, as it did so well in Vbscript. The "compiler" always run the line that deletes the playlist, but it doesn't get deleted.


However, the part where a track is being added to the new playlist is working well.


Anybody with good Python skills could please help me to debug this?

Thank you so much



# iTunes API

import win32com.client


iTunesApp = win32com.client.Dispatch("iTunes.Application")


def Cria_PL(PL_nome):

    PL = iTunesApp.LibrarySource.Playlists.ItemByName(PL_nome)

    if PL is not None:

       r= PL.delete

    # CRIA PLAYLIST  

    iTunesApp.CreatePlaylist(PL_nome)

    PL = iTunesApp.LibrarySource.Playlists.ItemByName(PL_nome)

   

    return PL

   

# CREATES PLAYLIST

New_PL = None

#Move_files

New_PL = Cria_PL("Test")


arq="D:/MP3/Favorites/Abba - Fernando.mp3"

print(arq)


New_PL.AddFile(arq)


New_PL = None    


Posted on Nov 15, 2021 6:59 PM

Reply
2 replies

Nov 15, 2021 7:56 PM in response to jrsousa2

I was able to fix the delete playlist, but now given Murphy's law, a problem that previously didn't happen is occurring.


Initially when I set a playlist object I didn't see "win32com.gen_py.iTunes 1.13", it was just "<COMObject ItemByName>". After it changed to this new value, now the AddFile method stopped working.


Besides, the VC code debugger is now stepping into even the com code, which drives me crazy, which didn't happen before.


Does anybody know how I can set things right as they were before (except for the delete playlist)?


Exception has occurred: AttributeError


'<win32com.gen_py.iTunes 1.13 Type Library.IITPlaylist instance at 0x2490957472192>' object has no attribute 'AddFile'

File "D:\iTunes\VS Code\Cria_PL.py", line 18, in Cria_PL

PL.AddFile("D:/MP3/Favorites/Abba - Fernando.mp3")

File "D:\iTunes\VS Code\Cria_PL.py", line 28, in <module>

New_PL = Cria_PL("xxx")

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Python code not working to delete an existing playlist

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.