From ca64d54b4eb1a9af0fb4b351a37f7e5d982830b5 Mon Sep 17 00:00:00 2001 From: croneter Date: Sun, 1 Nov 2020 16:10:44 +0100 Subject: [PATCH] Fix freeze: Don't assign multiple sets/collections for a specific movie --- resources/lib/itemtypes/movies.py | 73 +++++++++++++++++-------------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/resources/lib/itemtypes/movies.py b/resources/lib/itemtypes/movies.py index 1c17f395..67836312 100644 --- a/resources/lib/itemtypes/movies.py +++ b/resources/lib/itemtypes/movies.py @@ -140,39 +140,7 @@ class Movie(ItemBase): self.kodidb.modify_streams(file_id, api.mediastreams(), api.runtime()) self.kodidb.modify_studios(kodi_id, v.KODI_TYPE_MOVIE, api.studios()) tags = [section_name] - if api.collections(): - for plex_set_id, set_name in api.collections(): - set_api = None - tags.append(set_name) - # Add any sets from Plex collection tags - kodi_set_id = self.kodidb.create_collection(set_name) - self.kodidb.assign_collection(kodi_set_id, kodi_id) - if not app.SYNC.artwork: - # Rest below is to get collection artwork - continue - if children is None: - # e.g. when added via websocket - LOG.debug('Costly looking up Plex collection %s: %s', - plex_set_id, set_name) - for index, coll_plex_id in api.collections_match(section_id): - # Get Plex artwork for collections - a pain - if index == plex_set_id: - set_xml = PF.GetPlexMetadata(coll_plex_id) - try: - set_xml.attrib - except AttributeError: - LOG.error('Could not get set metadata %s', - coll_plex_id) - continue - set_api = API(set_xml[0]) - break - elif plex_set_id in children: - # Provided by get_metadata thread - set_api = API(children[plex_set_id][0]) - if set_api: - self.kodidb.modify_artwork(set_api.artwork(), - kodi_set_id, - v.KODI_TYPE_SET) + self._process_collections(api, tags, kodi_id, section_id, children) self.kodidb.modify_tags(kodi_id, v.KODI_TYPE_MOVIE, tags) # Process playstate self.kodidb.set_resume(file_id, @@ -246,3 +214,42 @@ class Movie(ItemBase): db_item['kodi_type'], api.userrating()) return True + + def _process_collections(self, api, tags, kodi_id, section_id, children): + for plex_set_id, set_name in api.collections(): + set_api = None + tags.append(set_name) + # Add any sets from Plex collection tags + kodi_set_id = self.kodidb.create_collection(set_name) + self.kodidb.assign_collection(kodi_set_id, kodi_id) + if not app.SYNC.artwork: + # Rest below is to get collection artwork + # TODO: continue instead of break (see TODO/break below) + break + if children is None: + # e.g. when added via websocket + LOG.debug('Costly looking up Plex collection %s: %s', + plex_set_id, set_name) + for index, coll_plex_id in api.collections_match(section_id): + # Get Plex artwork for collections - a pain + if index == plex_set_id: + set_xml = PF.GetPlexMetadata(coll_plex_id) + try: + set_xml.attrib + except AttributeError: + LOG.error('Could not get set metadata %s', + coll_plex_id) + continue + set_api = API(set_xml[0]) + break + elif plex_set_id in children: + # Provided by get_metadata thread + set_api = API(children[plex_set_id][0]) + if set_api: + self.kodidb.modify_artwork(set_api.artwork(), + kodi_set_id, + v.KODI_TYPE_SET) + # TODO: Once Kodi (19?) supports SEVERAL sets/collections per + # movie, support that. For now, we only take the very first + # collection/set that Plex returns + break