From 20f26364b8ebc9900c3bf53f5ac4c7f195714ac1 Mon Sep 17 00:00:00 2001 From: croneter Date: Tue, 6 Nov 2018 19:06:48 +0100 Subject: [PATCH] Enforce plex id type int --- resources/lib/playlist_func.py | 2 +- resources/lib/plex_api.py | 19 +++---------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/resources/lib/playlist_func.py b/resources/lib/playlist_func.py index 3c1920c7..8dbf175a 100644 --- a/resources/lib/playlist_func.py +++ b/resources/lib/playlist_func.py @@ -329,7 +329,7 @@ def playlist_item_from_kodi(kodi_item): item.file = kodi_item.get('file') if item.plex_id is None and item.file is not None: query = dict(parse_qsl(urlsplit(item.file).query)) - item.plex_id = query.get('plex_id') + item.plex_id = utils.cast(int, query.get('plex_id')) item.plex_type = query.get('itemType') if item.plex_id is None and item.file is not None: item.uri = ('library://whatever/item/%s' diff --git a/resources/lib/plex_api.py b/resources/lib/plex_api.py index b8bd4861..c92a8e05 100644 --- a/resources/lib/plex_api.py +++ b/resources/lib/plex_api.py @@ -54,19 +54,6 @@ LOG = getLogger('PLEX.plex_api') ############################################################################### -def _unicode_or_none(value): - """ - Tries to decode value to unicode. Returns None if this fails - """ - try: - return value.decode('utf-8') - except TypeError: - # e.g. Android TV's Python - return value.decode() - except AttributeError: - pass - - class API(object): """ API(item) @@ -94,7 +81,7 @@ class API(object): Returns the type of media, e.g. 'movie' or 'clip' for trailers as Unicode or None. """ - return _unicode_or_none(self.item.get('type')) + return self.item.get('type') def playlist_type(self): """ @@ -713,8 +700,8 @@ class API(object): as Unicode. If not found, None is returned """ - return _unicode_or_none(self.item.get('playQueueItemID') or - self.item.get('playListItemID')) + return (cast(int, self.item.get('playQueueItemID')) or + cast(int, self.item.get('playListItemID'))) def _data_from_part_or_media(self, key): """