From adf5f84ffd74784e60b2b6a39ccd5c9b12019ed3 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Sat, 28 Jan 2023 19:07:04 -0500 Subject: [PATCH] [40] add log-requests env variable --- VERSION | 2 +- defaults/translations/default.yml | 4 +-- docs/home/environmental.md | 36 ++++++++++++++++++++++++- modules/builder.py | 44 +++++++++++++++---------------- modules/logs.py | 5 ++-- plex_meta_manager.py | 4 ++- 6 files changed, 66 insertions(+), 29 deletions(-) diff --git a/VERSION b/VERSION index 5643a049..f6af389d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.18.3-develop39 +1.18.3-develop40 diff --git a/defaults/translations/default.yml b/defaults/translations/default.yml index be497457..08a70476 100644 --- a/defaults/translations/default.yml +++ b/defaults/translations/default.yml @@ -430,8 +430,8 @@ translations: audio_language_other_summary: <>s filmed in other uncommon Languages. # possible key_names: Book, Comic, True Story, Video Game - basedon_name: Based on a <> - basedon_summary: <>s based on or inspired by <>s. + based_name: Based on a <> + based_summary: <>s based on or inspired by <>s. collectionless_name: Collectionless collectionless_summary: Collection of <>s used to make Plex display items correctly. diff --git a/docs/home/environmental.md b/docs/home/environmental.md index b7337dd5..8fd7f668 100644 --- a/docs/home/environmental.md +++ b/docs/home/environmental.md @@ -14,6 +14,7 @@ These docs are assuming you have a basic understanding of Docker concepts. One | [Run Tests](#run-tests) | `-rt`, `--tests`, or `--run-tests` | `PMM_TEST` | | [Debug](#debug) | `-db` or `--debug` | `PMM_DEBUG` | | [Trace](#trace) | `-tr` or `--trace` | `PMM_TRACE` | +| [Log Requests](#log-requests) | `-lr` or `--log-requests` | `PMM_LOG_REQUESTS` | | [Timeout](#timeout) | `-ti` or `--timeout` | `PMM_TIMEOUT` | | [Collections Only](#collections-only) | `-co` or `--collections-only` | `PMM_COLLECTIONS_ONLY` | | [Playlists Only](#playlists-only) | `-po` or `--playlists-only` | `PMM_PLAYLISTS_ONLY` | @@ -257,7 +258,40 @@ python plex_meta_manager.py --trace ```` ````{tab} Docker Environment ``` -docker run -it -v "X:\Media\Plex Meta Manager\config:/config:rw" meisnate12/plex-meta-manager --trace0 +docker run -it -v "X:\Media\Plex Meta Manager\config:/config:rw" meisnate12/plex-meta-manager --trace +``` +```` + +### Log Requests + +Run with every network request printed to the Logs. **This can potentially have personal information in it.** + + + + + + + + + + + + + + + + + +
ShellEnvironment
Flags-lr or --log-request or --log-requestsPMM_LOG_REQUESTS
Example--log-requestsPMM_NETWORK=true
+ +````{tab} Local Environment +``` +python plex_meta_manager.py --log-requests +``` +```` +````{tab} Docker Environment +``` +docker run -it -v "X:\Media\Plex Meta Manager\config:/config:rw" meisnate12/plex-meta-manager --log-requests ``` ```` diff --git a/modules/builder.py b/modules/builder.py index 4b3428d6..84bd091c 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -2100,6 +2100,28 @@ class CollectionBuilder: return util.validate_regex(data, self.Type, validate=validate) elif attribute in string_attributes and modifier in ["", ".not", ".is", ".isnot", ".begins", ".ends"]: return smart_pair(util.get_list(data, split=False)) + elif attribute in year_attributes and modifier in ["", ".not", ".gt", ".gte", ".lt", ".lte"]: + if modifier in ["", ".not"]: + final_years = [] + values = util.get_list(data) + for value in values: + if str(value).startswith("current_year"): + year_values = str(value).split("-") + try: + final_years.append(datetime.now().year - (0 if len(year_values) == 1 else int(year_values[1].strip()))) + except ValueError: + raise Failed(f"{self.Type} Error: {final} attribute modifier invalid '{year_values[1]}'") + else: + final_years.append(util.parse(self.Type, final, value, datatype="int")) + return smart_pair(final_years) + else: + if str(data).startswith("current_year"): + year_values = str(data).split("-") + try: + return datetime.now().year - (0 if len(year_values) == 1 else int(year_values[1].strip())) + except ValueError: + raise Failed(f"{self.Type} Error: {final} attribute modifier invalid '{year_values[1]}'") + return util.parse(self.Type, final, data, datatype="int", minimum=0) elif (attribute in number_attributes and modifier in ["", ".not", ".gt", ".gte", ".lt", ".lte"]) \ or (attribute in tag_attributes and modifier in [".count_gt", ".count_gte", ".count_lt", ".count_lte"]): return util.parse(self.Type, final, data, datatype="int", minimum=0) @@ -2174,28 +2196,6 @@ class CollectionBuilder: return datetime.strftime(datetime.now(), "%Y-%m-%d") else: return util.validate_date(data, final, return_as="%Y-%m-%d") - elif attribute in year_attributes and modifier in ["", ".not", ".gt", ".gte", ".lt", ".lte"]: - if modifier in ["", ".not"]: - final_years = [] - values = util.get_list(data) - for value in values: - if str(value).startswith("current_year"): - year_values = str(value).split("-") - try: - final_years.append(datetime.now().year - (0 if len(year_values) == 1 else int(year_values[1].strip()))) - except ValueError: - raise Failed(f"{self.Type} Error: {final} attribute modifier invalid '{year_values[1]}'") - else: - final_years.append(util.parse(self.Type, final, value, datatype="int")) - return smart_pair(final_years) - else: - if str(data).startswith("current_year"): - year_values = str(data).split("-") - try: - return datetime.now().year - (0 if len(year_values) == 1 else int(year_values[1].strip())) - except ValueError: - raise Failed(f"{self.Type} Error: {final} attribute modifier invalid '{year_values[1]}'") - return util.parse(self.Type, final, data, datatype="int", minimum=0) elif attribute in date_attributes and modifier in ["", ".not"]: search_mod = "d" if plex_search and data and str(data)[-1] in ["s", "m", "h", "d", "w", "o", "y"]: diff --git a/modules/logs.py b/modules/logs.py index b0f80de8..072d34b4 100644 --- a/modules/logs.py +++ b/modules/logs.py @@ -29,13 +29,14 @@ _srcfile = os.path.normcase(fmt_filter.__code__.co_filename) class MyLogger: - def __init__(self, logger_name, default_dir, screen_width, separating_character, ignore_ghost, is_debug, is_trace): + def __init__(self, logger_name, default_dir, screen_width, separating_character, ignore_ghost, is_debug, is_trace, log_requests): self.logger_name = logger_name self.default_dir = default_dir self.screen_width = screen_width self.separating_character = separating_character self.is_debug = is_debug self.is_trace = is_trace + self.log_requests = log_requests self.ignore_ghost = ignore_ghost self.log_dir = os.path.join(default_dir, LOG_DIR) self.playlists_dir = os.path.join(self.log_dir, PLAYLIST_DIR) @@ -51,7 +52,7 @@ class MyLogger: self.spacing = 0 self.playlists_log = os.path.join(self.playlists_dir, PLAYLISTS_LOG) os.makedirs(self.log_dir, exist_ok=True) - self._logger = logging.getLogger(self.logger_name) + self._logger = logging.getLogger(None if self.log_requests else self.logger_name) self._logger.setLevel(logging.DEBUG) cmd_handler = logging.StreamHandler() diff --git a/plex_meta_manager.py b/plex_meta_manager.py index 4254e610..c7a94fe8 100644 --- a/plex_meta_manager.py +++ b/plex_meta_manager.py @@ -21,6 +21,7 @@ if sys.version_info[0] != 3 or sys.version_info[1] < 7: parser = argparse.ArgumentParser() parser.add_argument("-db", "--debug", dest="debug", help="Run with Debug Logs Reporting to the Command Window", action="store_true", default=False) parser.add_argument("-tr", "--trace", dest="trace", help="Run with extra Trace Debug Logs", action="store_true", default=False) +parser.add_argument("-lr", "--log-request", "log-requests", dest="log_requests", help="Run with all Requests printed", action="store_true", default=False) parser.add_argument("-c", "--config", dest="config", help="Run with desired *.yml file", type=str) parser.add_argument("-t", "--time", "--times", dest="times", help="Times to update each day use format HH:MM (Default: 05:00) (comma-separated list)", default="05:00", type=str) parser.add_argument("-ti", "--timeout", dest="timeout", help="PMM Global Timeout (Default: 180)", default=180, type=int) @@ -118,6 +119,7 @@ screen_width = get_arg("PMM_WIDTH", args.width, arg_int=True) timeout = get_arg("PMM_TIMEOUT", args.timeout, arg_int=True) debug = get_arg("PMM_DEBUG", args.debug, arg_bool=True) trace = get_arg("PMM_TRACE", args.trace, arg_bool=True) +log_requests = get_arg("PMM_LOG_REQUESTS", args.log_requests, arg_bool=True) plex_url = get_arg("PMM_PLEX_URL", args.plex_url) plex_token = get_arg("PMM_PLEX_TOKEN", args.plex_token) @@ -138,7 +140,7 @@ elif not os.path.exists(os.path.join(default_dir, "config.yml")): print(f"Config Error: config not found at {os.path.abspath(default_dir)}") sys.exit(0) -logger = MyLogger("Plex Meta Manager", default_dir, screen_width, divider[0], ignore_ghost, test or debug, trace) +logger = MyLogger("Plex Meta Manager", default_dir, screen_width, divider[0], ignore_ghost, test or debug, trace, log_requests) from modules import util util.logger = logger