JordyAlkema / Youtube-DL-Agent.bundle

A plex metadata agent for Youtube-DL downloads
119 stars 14 forks source link

Safely access metadata #13

Closed benortiz closed 2 years ago

benortiz commented 2 years ago

When a key is missing from info.json, it shouldn't prevent the rest of the data from being loaded.

When adding an item that wasn't a part of a playlist, there will be no 'playlist_title'. Before this change, all the metadata would be missing from these videos. Now, the other data gets loaded. Yay!

I tried to replecate the pattern already established of using:

if data['key']:

but this raised the same KeyError when the key didn't exist. I'm not a regular Python dev but I think something changed in Python 3. Using the in syntax here seems to work great for all the places I changed.

I think this should address:

https://github.com/JordyAlkema/Youtube-DL-Agent.bundle/issues/6#issuecomment-912676366 https://github.com/JordyAlkema/Youtube-DL-Agent.bundle/issues/10#issuecomment-961840829 https://github.com/JordyAlkema/Youtube-DL-Agent.bundle/issues/12

As the issue they describe has the same symptoms that I was experiencing.

JordyAlkema commented 2 years ago

Thank you for taking the time to look into the issue and making a pull request!