fixed collection tags on remove

This commit is contained in:
meisnate12 2021-09-30 16:55:29 -04:00
parent fd84674cac
commit cef150bec0
2 changed files with 11 additions and 11 deletions

View file

@ -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")

View file

@ -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"