From b4f1086dbca58d9511fa8bcc16df5036c0a5ca45 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Tue, 8 Feb 2022 21:31:29 -0500 Subject: [PATCH] #661 fixed minimum_items --- VERSION | 2 +- modules/builder.py | 13 +++++++------ plex_meta_manager.py | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/VERSION b/VERSION index 9f274f02..f5aaa671 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.15.1-develop59 +1.15.1-develop60 diff --git a/modules/builder.py b/modules/builder.py index 7d26263e..c6079362 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -288,10 +288,12 @@ class CollectionBuilder: self.notification_additions = [] self.notification_removals = [] self.items = [] + self.remove_item_map = {} self.posters = {} self.backgrounds = {} self.summaries = {} self.schedule = "" + self.beginning_count = 0 self.minimum = self.library.minimum_items self.ignore_ids = [i for i in self.library.ignore_ids] self.ignore_imdb_ids = [i for i in self.library.ignore_imdb_ids] @@ -689,12 +691,11 @@ class CollectionBuilder: except Failed: self.obj = None - self.plex_map = {} - if self.sync and self.obj: - for item in self.library.get_collection_items(self.obj, self.smart_label_collection): - self.plex_map[item.ratingKey] = item if self.obj: self.exists = True + self.beginning_count = self.obj.childCount + if self.sync: + self.remove_item_map = {i.ratingKey: i for i in self.library.get_collection_items(self.obj, self.smart_label_collection)} else: self.obj = None self.sync = False @@ -1780,7 +1781,7 @@ class CollectionBuilder: number_text = f"{i}/{total}" logger.info(util.adjust_space(f"{number_text:>{spacing}} | {name} {self.Type} | {current_operation} | {util.item_title(item)}")) if item in collection_items: - self.plex_map[item.ratingKey] = None + self.remove_item_map[item.ratingKey] = None amount_unchanged += 1 else: if self.playlist: @@ -1810,7 +1811,7 @@ class CollectionBuilder: def sync_collection(self): amount_removed = 0 playlist_removes = [] - items = [item for _, item in self.plex_map.items() if item is not None] + items = [item for _, item in self.remove_item_map.items() if item is not None] if items: logger.info("") util.separator(f"Removed from {self.name} {self.Type}", space=False, border=False) diff --git a/plex_meta_manager.py b/plex_meta_manager.py index e923b885..83141f9a 100644 --- a/plex_meta_manager.py +++ b/plex_meta_manager.py @@ -879,7 +879,7 @@ def run_collection(config, library, metadata, requested_collections): logger.info("") builder.filter_and_save_items(builder.gather_ids(method, value)) - if len(builder.added_items) >= builder.minimum and builder.build_collection: + if len(builder.added_items) > 0 and len(builder.added_items) + builder.beginning_count >= builder.minimum and builder.build_collection: items_added, items_unchanged = builder.add_to_collection() library.stats["added"] += items_added library.status[mapping_name]["added"] = items_added @@ -890,7 +890,7 @@ def run_collection(config, library, metadata, requested_collections): items_removed = builder.sync_collection() library.stats["removed"] += items_removed library.status[mapping_name]["removed"] = items_removed - elif len(builder.added_items) < builder.minimum and builder.build_collection: + elif len(builder.added_items) + builder.beginning_count < builder.minimum and builder.build_collection: logger.info("") logger.info(f"Collection Minimum: {builder.minimum} not met for {mapping_name} Collection") valid = False