From 36eaf230b5110aaf1d69f248711fa1cec3a4ec3d Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Mon, 9 Jan 2023 09:56:40 -0500 Subject: [PATCH 1/3] [10] fix ignoring translation variables --- VERSION | 2 +- modules/meta.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index 8657c968..c7d11a12 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.18.2-develop9 +1.18.2-develop10 diff --git a/modules/meta.py b/modules/meta.py index 54c0e192..aef14829 100644 --- a/modules/meta.py +++ b/modules/meta.py @@ -306,8 +306,8 @@ class DataFile: conditionals[k] = v language = variables["language"] if "language" in variables else "default" - translation_variables = {k: v[language if language in v else "default"] for k, v in self.translations.items()} - translation_variables.update({k: v[language if language in v else "default"] for k, v in self.translation_variables.items() if language in v or "default" in v}) + translation_variables = {k: v[language if language in v else "default"] for k, v in self.translations.items() if k not in optional} + translation_variables.update({k: v[language if language in v else "default"] for k, v in self.translation_variables.items() if (language in v or "default" in v) and k not in optional}) key_name_variables = {} for var_key, var_value in self.key_names.items(): if var_key == "library_type" and language in var_value: From 0afb24333546a94bbb728127be6ecbe8f6d603eb Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Mon, 9 Jan 2023 16:22:39 -0500 Subject: [PATCH 2/3] [11] add summary output to log --- VERSION | 2 +- modules/library.py | 3 +-- modules/util.py | 4 ++-- plex_meta_manager.py | 27 +++++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index c7d11a12..f516d6e5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.18.2-develop10 +1.18.2-develop11 diff --git a/modules/library.py b/modules/library.py index 828e58f2..329596e7 100644 --- a/modules/library.py +++ b/modules/library.py @@ -279,8 +279,7 @@ class Library(ABC): self.report_data[collection][other] = [] self.report_data[collection][other].append(title) - with open(self.report_path, "w"): pass - yaml = YAML(self.report_path) + yaml = YAML(self.report_path, start_empty=True) yaml.data = self.report_data yaml.save() diff --git a/modules/util.py b/modules/util.py index 18674465..ff69d5e5 100644 --- a/modules/util.py +++ b/modules/util.py @@ -931,7 +931,7 @@ def get_system_fonts(): return system_fonts class YAML: - def __init__(self, path=None, input_data=None, check_empty=False, create=False): + def __init__(self, path=None, input_data=None, check_empty=False, create=False, start_empty=False): self.path = path self.input_data = input_data self.yaml = ruamel.yaml.YAML() @@ -940,7 +940,7 @@ class YAML: if input_data: self.data = self.yaml.load(input_data) else: - if create and not os.path.exists(self.path): + if start_empty or (create and not os.path.exists(self.path)): with open(self.path, 'w'): pass self.data = {} diff --git a/plex_meta_manager.py b/plex_meta_manager.py index 729c32e0..c5f56163 100644 --- a/plex_meta_manager.py +++ b/plex_meta_manager.py @@ -1,4 +1,5 @@ import argparse, os, platform, psutil, sys, time, uuid +from collections import Counter from concurrent.futures import ProcessPoolExecutor from datetime import datetime from modules.logs import MyLogger @@ -274,6 +275,32 @@ def start(attrs): version_line = f"Version: {version[0]}" if new_version: version_line = f"{version_line} Newest Version: {new_version}" + try: + log_data = {} + with open(logger.main_log, encoding="utf-8") as f: + for log_line in f: + for err_type in ["WARNING", "ERROR", "CRITICAL"]: + if f"[{err_type}]" in log_line: + log_line = log_line.split("|")[1].strip() + if err_type not in log_data: + log_data[err_type] = [] + log_data[err_type].append(log_line) + + for err_type in ["WARNING", "ERROR", "CRITICAL"]: + if err_type not in log_data: + continue + logger.separator(f"{err_type.lower().capitalize()} Summary", space=False, border=False) + + logger.info("") + logger.info(f"Count | Message") + logger.separator(f"{logger.separating_character * 5}|", space=False, border=False, side_space=False, left=True) + for k, v in Counter(log_data[err_type]).most_common(): + logger.info(f"{v:>5} | {k}") + logger.info("") + except Failed as e: + logger.stacktrace() + logger.error(f"Report Error: {e}") + logger.separator(f"Finished {start_type}Run\n{version_line}\nFinished: {end_time.strftime('%H:%M:%S %Y-%m-%d')} Run Time: {run_time}") logger.remove_main_handler() From 2311ebd3f928ed55894ec598c9983bb97fbf5ba0 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Mon, 9 Jan 2023 17:01:02 -0500 Subject: [PATCH 3/3] [12] allow template operations --- VERSION | 2 +- modules/meta.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index f516d6e5..19d8f8c9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.18.2-develop11 +1.18.2-develop12 diff --git a/modules/meta.py b/modules/meta.py index aef14829..f137a6b0 100644 --- a/modules/meta.py +++ b/modules/meta.py @@ -474,8 +474,16 @@ class DataFile: return og_txt elif str(og_txt) == f"<<{var}>>": return actual_value - elif f"<<{var}>>" in str(og_txt): - return str(og_txt).replace(f"<<{var}>>", str(actual_value)) + elif f"<<{var}" in str(og_txt): + final = str(og_txt).replace(f"<<{var}>>", str(actual_value)) if f"<<{var}>>" in str(og_txt) else str(og_txt) + if f"<<{var}" in final: + match = re.search(f"<<({var}([+-])(\d+))>>", final) + if match: + try: + final = final.replace(f"<<{match.group(1)}>>", str(int(actual_value) + (int(match.group(3)) * (-1 if match.group(2) == "-" else 1)))) + except ValueError: + raise Failed(f"Template Error: {actual_value} must be a number to use {match.group(1)}") + return final else: return og_txt if _debug: