I've got a small script to create/maintain a randomized rolling 25-song playlist in iTunes which emulates some of the behaviour of an iTunes feature called Party Shuffle or iTunes DJ, which was removed from the iTunes app year ago. I've got its playback behaviour figured out and working except I seem to have come across a bug that seems to be causing data corruption somehow. The script was erroring out occasionally when trying to execute a playlist.AddTrack(song) command with error messages like this:
Traceback (most recent call last): File "C:\iTunesDJ-project\iTunesDJ-current working version-debugging4.py", line 138, in <module> playlist.AddTrack(song) File "<COMObject <unknown>>", line 2, in AddTrack pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, 'The track has been deleted.', None, 0, -1610350078), None) Error printing song.Name: I tried troubleshooting and added some print statements, and when it tried printing song.Name it gave a similar error: Traceback (most recent call last): File "C:\iTunesDJ-project\iTunesDJ-current working version-debugging.py", line 138, in <module> print("song.Name:", song.Name) ^^^^^^^^^ File "C:\Users\Clay\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\win32com\client\dynamic.py", line 628, in __getattr__ ret = self._oleobj_.Invoke(retEntry.dispid, 0, invoke_type, 1) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, 'The track has been deleted.', None, 0, -1610350078), None) I pared the script down so that the only things it was doing was connecting to iTunes to get the song library list and then doing a loop where it printed song.Name for random entries 1,000 times using "try" so it would continue if there was an error. This worked perfectly, so I was confused. I started adding commands back in one at a time until it finally started producing errors after a playlist.Tracks[0].Delete() command was executed. I can now reproduce the problem very easily. Only 1/20 trials ran without error once I reintroduced the delete command. 19/20 trials produced hundreds of errors in the 1,000 attempts in the loop. I don't know if you'd want ~150 lines of code included here or not, but the script can be downloaded from here if you'd like to see the whole thing. https://drive.google.com/file/d/1HMuZV7W1xDvYkkrbQ0O2wgJ782VLYqPa/view?usp=sharing -- Clayton Macleod If no one comes from the future to stop you from doing it, then how bad of a decision can it really be?
_______________________________________________ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32