electronut / pp

Code for book Python Playground by Mahesh Venkitachalam (No Starch Press, USA)
568 stars 499 forks source link

Not finding duplicates... #27

Closed nnanook9 closed 4 years ago

nnanook9 commented 4 years ago

Even with a simple playlist I made specifically for testing that only contains the same song 3 times, the code is not finding duplicates. Tried with the 'test files' too - same result. Issue appears to be that the xml file only lists the tracks once, and then refers to them as many times as required further down in the Playlist Items dictionary. The code looks for duplicates in the Tracks dictionary - but the xml file doesn't repeat duplicates there, so the code always returns no duplicates.

Has the plist format changed since this code was written, or am I missing something else?

xhf79 commented 4 years ago

Would you please paste your code?

nnanook9 commented 4 years ago

I used the code from this repository...no edits made. I believe the issue is that the code in the book, and as provided here, are both searching the wrong portion of the plist xml file from iTunes, when looking for duplicates.

nnanook9 commented 4 years ago

Here is the playlist file I am using to test the code. This playlist contains the same song 3 times, and nothing else.

testcode.txt

The issue appears to be that the code from the Python Playground book is looking for duplicates in the 'tracks' section of the playlist file, but duplicates do not actually show up there. Repeated tracks metadata is only shown once. The duplicates show up in the 'playlist' part of the file, where the track ID is shown multiple times. This is not pulled into the code, so it isn't searched.

xhf79 commented 4 years ago

001 002

nnanook9 commented 4 years ago

Thanks for the follow up. I am completely lost as to what I am missing. Did you run the code exactly as currently in the repo?

Do you have any insight on what I must be confused about in my questions above?

Really appreciate your time!

xhf79 commented 4 years ago

Yeah, I use the same code in the repo and the same file you pasted. Did you use windows system? It should be run in cmd, not in python idle.

nnanook9 commented 4 years ago

I’m running it in on a Mac using Thonny. It accepts the command line arguments, and pulls in the plist file ok. And when I step through in debug it seems to be behaving. I am just not understanding how the code (in the repo) sees the duplicates, as it doesn’t seem to me that the part of the file is being evaluated.

Clearly I am missing something!

nnanook9 commented 4 years ago

Yeah, I use the same code in the repo and the same file you pasted. Did you use windows system? It should be run in cmd, not in python idle.

Interesting that your screen grab of the output file doesn't show the number of duplicates found for the track, next to the track name, like this:

[2] Skyfall

...seeing as that is how the code writes that output file.


    for val in dups:
        f.write("[%d] %s\n" % (val[0], val[1]))
    f.close()```
nnanook9 commented 4 years ago

I did finally get to the bottom of this...the code will find duplicates that have different TrackID numbers. If you make a playlist that just repeats the same song file, then that isn't counted as a duplicate.