Skip to content

Commit b754178

Browse files
authored
Merge pull request #3 from tmcarr/patch-1
Add some error catching around metadata fields
2 parents f2efe18 + 8342503 commit b754178

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

custom_components/sensor/plex_recently_added.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,12 @@ def update(self):
204204
"""Get JSON for each library, combine and sort."""
205205
for library in sections:
206206
sub_sec = plex.get(recently_added.format(
207-
library, self.max_items * 2), headers=headers, timeout=10)
208-
self.api_json += sub_sec.json()['MediaContainer']['Metadata']
207+
library, self.max_items * 2), headers=headers, timeout=10)
208+
try:
209+
self.api_json += sub_sec.json()['MediaContainer']['Metadata']
210+
except:
211+
_LOGGER.warning('No Metadata field for "{}"'.format(sub_sec.json()['MediaContainer']['librarySectionTitle']))
212+
pass
209213
self.api_json = sorted(self.api_json, key=lambda i: i['addedAt'],
210214
reverse=True)[:self.max_items]
211215
overview = get_info(self.api_json[0].get('title', ''))

0 commit comments

Comments
 (0)