From 1128edcafef5f82110a0913297e9c1f0b03c2133 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Sat, 19 Nov 2022 15:17:43 -0500 Subject: [PATCH] [27] update smart collection counts --- VERSION | 2 +- modules/builder.py | 21 +++++++++++---------- modules/logs.py | 2 +- plex_meta_manager.py | 11 +++++------ 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/VERSION b/VERSION index 3233802f..3d0ed3b1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.18.0-develop26 +1.18.0-develop27 diff --git a/modules/builder.py b/modules/builder.py index dc4469d1..3f289826 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -423,6 +423,7 @@ class CollectionBuilder: self.ignore_blank_results = util.parse(self.Type, "ignore_blank_results", self.data, datatype="bool", methods=methods, default=True) self.smart_filter_details = "" + self.smart_label_url = None self.smart_label = {"sort_by": "random", "all": {"label": [self.name]}} self.smart_label_collection = False if "smart_label" in methods and not self.playlist and not self.overlay and not self.library.is_music: @@ -445,7 +446,7 @@ class CollectionBuilder: logger.warning(f"{self.Type} Error: smart_label attribute: {self.data[methods['smart_label']]} is invalid defaulting to random") if self.smart_label_collection and self.library.smart_label_check(self.name): try: - _, self.smart_filter_details, _ = self.build_filter("smart_label", self.smart_label, default_sort="random") + _, self.smart_filter_details, self.smart_label_url = self.build_filter("smart_label", self.smart_label, default_sort="random") except FilterFailed as e: if self.ignore_blank_results: raise @@ -649,7 +650,7 @@ class CollectionBuilder: if isinstance(self.custom_sort, list) and not self.custom_sort: raise Failed(f"{self.Type} Error: {test_sort} collection_order invalid\n\trelease (Order Collection by release dates)\n\talpha (Order Collection Alphabetically)\n\tcustom (Custom Order Collection)\n\tOther sorting options can be found at https://github.com/meisnate12/Plex-Meta-Manager/wiki/Smart-Builders#sort-options") - if self.smart_url or self.smart_label_collection: + if self.smart: self.custom_sort = False for method_key, method_data in self.data.items(): @@ -810,14 +811,18 @@ class CollectionBuilder: self.obj = None except Failed: self.obj = None - + if self.smart: + check_url = self.smart_url if self.smart_url else self.smart_label_url + if self.obj and check_url != self.library.smart_filter(self.obj): + self.library.update_smart_collection(self.obj, check_url) + logger.info(f"Detail: Smart Collection updated to {check_url}") + self.beginning_count = len(self.library.get_filter_items(check_url)) if self.obj: self.exists = True if self.sync or self.playlist: self.remove_item_map = {i.ratingKey: i for i in self.library.get_collection_items(self.obj, self.smart_label_collection)} - self.beginning_count = len(self.remove_item_map) if self.playlist else self.obj.childCount - elif self.smart_label_collection: - self.beginning_count = len(self.library.search(label=self.name)) + if not self.smart: + self.beginning_count = len(self.remove_item_map) if self.playlist else self.obj.childCount else: self.obj = None self.sync = False @@ -2553,10 +2558,6 @@ class CollectionBuilder: logger.info("") logger.separator(f"Updating Details of {self.name} {self.Type}", space=False, border=False) logger.info("") - if self.smart_url and self.smart_url != self.library.smart_filter(self.obj): - self.library.update_smart_collection(self.obj, self.smart_url) - logger.info(f"Detail: Smart Filter updated to {self.smart_url}") - updated_details.append("Smart Filter") if "summary" in self.summaries: summary = ("summary", self.summaries["summary"]) elif "tmdb_description" in self.summaries: summary = ("tmdb_description", self.summaries["tmdb_description"]) elif "letterboxd_description" in self.summaries: summary = ("letterboxd_description", self.summaries["letterboxd_description"]) diff --git a/modules/logs.py b/modules/logs.py index d7af605e..abc0132f 100644 --- a/modules/logs.py +++ b/modules/logs.py @@ -226,7 +226,7 @@ class MyLogger: self.spacing = 0 def secret(self, text): - if str(text) not in self.secrets: + if text and str(text) not in self.secrets: self.secrets.append(str(text)) def _log(self, level, msg, args, exc_info=None, extra=None, stack_info=False, stacklevel=1): diff --git a/plex_meta_manager.py b/plex_meta_manager.py index 96e74024..4b1b348d 100644 --- a/plex_meta_manager.py +++ b/plex_meta_manager.py @@ -183,12 +183,12 @@ def start(attrs): logger.info_center(" |___/ ") system_ver = "Docker" if is_docker else f"Python {platform.python_version()}" logger.info(f" Version: {version[0]} ({system_ver})") - logger.info(f" Platform: {platform.platform()}") - logger.info(f" Memory: {round(psutil.virtual_memory().total / (1024.0 ** 3))} GB") latest_version = util.current_version(version) new_version = latest_version[0] if latest_version and (version[1] != latest_version[1] or (version[2] and version[2] < latest_version[2])) else None if new_version: logger.info(f" Newest Version: {new_version}") + logger.info(f" Platform: {platform.platform()}") + logger.info(f" Memory: {round(psutil.virtual_memory().total / (1024.0 ** 3))} GB") if "time" in attrs and attrs["time"]: start_type = f"{attrs['time']} " elif "test" in attrs and attrs["test"]: start_type = "Test " elif "collections" in attrs and attrs["collections"]: start_type = "Collections " @@ -604,6 +604,8 @@ def run_collection(config, library, metadata, requested_collections): if len(builder.smart_filter_details) > 0: logger.info("") logger.info(builder.smart_filter_details) + logger.info("") + logger.info(f"Items Found: {builder.beginning_count}") items_added = 0 items_removed = 0 @@ -648,10 +650,7 @@ def run_collection(config, library, metadata, requested_collections): library.status[str(mapping_name)]["sonarr"] += sonarr_add valid = True - if builder.build_collection and not builder.blank_collection and ( - (not builder.smart_url and items_added + builder.beginning_count < builder.minimum) - or (builder.smart_url and len(library.get_filter_items(builder.smart_url)) < builder.minimum) - ): + if builder.build_collection and not builder.blank_collection and items_added + builder.beginning_count < builder.minimum: logger.info("") logger.info(f"{builder.Type} Minimum: {builder.minimum} not met for {mapping_name} Collection") delete_status = f"Minimum {builder.minimum} Not Met"