From cef150bec0e8e8e0c480fa95822552f0ce2e0008 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Thu, 30 Sep 2021 16:55:29 -0400 Subject: [PATCH] fixed collection tags on remove --- modules/builder.py | 9 +++------ modules/plex.py | 13 ++++++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/builder.py b/modules/builder.py index 4ce5d578..96cbe2b5 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -1485,7 +1485,7 @@ class CollectionBuilder: if current in collection_items: self.plex_map[current.ratingKey] = None else: - self.library.add_to_collection(current, name, smart_label_collection=self.smart_label_collection) + self.library.alter_collection(current, name, smart_label_collection=self.smart_label_collection) util.print_end() logger.info("") logger.info(f"{total} {self.collection_level.capitalize()}{'s' if total > 1 else ''} Processed") @@ -1713,10 +1713,7 @@ class CollectionBuilder: logger.info("") self.library.reload(item) logger.info(f"{self.name} Collection | - | {self.item_title(item)}") - if self.smart_label_collection: - self.library.query_data(item.removeLabel, self.name) - else: - self.library.query_data(item.removeCollection, self.name) + self.library.alter_collection(item, self.name, smart_label_collection=self.smart_label_collection, add=False) count_removed += 1 if count_removed > 0: logger.info("") @@ -2026,7 +2023,7 @@ class CollectionBuilder: if current in collection_items: logger.info(f"{name} Collection | = | {self.item_title(current)}") else: - self.library.add_to_collection(current, name, smart_label_collection=self.smart_label_collection) + self.library.alter_collection(current, name, smart_label_collection=self.smart_label_collection) logger.info(f"{name} Collection | + | {self.item_title(current)}") logger.info(f"{len(rating_keys)} {self.collection_level.capitalize()}{'s' if len(rating_keys) > 1 else ''} Processed") diff --git a/modules/plex.py b/modules/plex.py index 1991639b..f44d7cf0 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -303,8 +303,11 @@ class Plex(Library): return method(data) @retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_failed) - def query_collection(self, item, collection, locked=True): - item.addCollection(collection, locked=locked) + def query_collection(self, item, collection, locked=True, add=True): + if add: + item.addCollection(collection, locked=locked) + else: + item.removeCollection(collection, locked=locked) @retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_plex) def collection_mode_query(self, collection, data): @@ -384,15 +387,15 @@ class Plex(Library): else: method = None return self.Plex._server.query(key, method=method) - def add_to_collection(self, item, collection, smart_label_collection=False): + def alter_collection(self, item, collection, smart_label_collection=False, add=True): if smart_label_collection: - self.query_data(item.addLabel, collection) + self.query_data(item.addLabel if add else item.removeLabel, collection) else: locked = True if self.agent in ["tv.plex.agents.movie", "tv.plex.agents.series"]: field = next((f for f in item.fields if f.name == "collection"), None) locked = field is not None - self.query_collection(item, collection, locked=locked) + self.query_collection(item, collection, locked=locked, add=add) def move_item(self, collection, item, after=None): key = f"{collection.key}/items/{item}/move"