From aba08397f4471873c05b3d89d09440e0b8ff2e5f Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Mon, 19 Dec 2022 20:04:14 -0500 Subject: [PATCH] [67] add url to ENV var --- VERSION | 2 +- docs/config/plex.md | 16 +++++------ docs/home/environmental.md | 58 ++++++++++++++++++++++++++++++++++++++ modules/config.py | 6 ++++ plex_meta_manager.py | 8 ++++++ 5 files changed, 81 insertions(+), 9 deletions(-) diff --git a/VERSION b/VERSION index 99d46389..9a907fe9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.18.0-develop66 +1.18.0-develop67 diff --git a/docs/config/plex.md b/docs/config/plex.md index 2e6fc255..85dcae3c 100644 --- a/docs/config/plex.md +++ b/docs/config/plex.md @@ -15,14 +15,14 @@ plex: optimize: false ``` -| Attribute | Allowed Values | Default | Required | -|:----------------|:-----------------------------------------------------------------------|:--------|:--------:| -| `url` | Plex Server URL
Example: http://192.168.1.12:32400 | N/A | ✅ | -| `token` | Plex Server Authentication Token | N/A | ✅ | -| `timeout` | Plex Server Timeout | 60 | ❌ | -| `clean_bundles` | Runs Clean Bundles on the Server after all Metadata Files are run | false | ❌ | -| `empty_trash` | Runs Empty Trash on the Server after all Metadata Files are run | false | ❌ | -| `optimize` | Runs Optimize on the Server after all Metadata Files are run | false | ❌ | +| Attribute | Allowed Values | Default | Required | +|:----------------|:---------------------------------------------------------------------------------------------------------------------------------|:--------|:--------:| +| `url` | Plex Server URL or `ENV` (This will use the Environment/Runtime Plex URL)
Example: http://192.168.1.12:32400 | N/A | ✅ | +| `token` | Plex Server Authentication Token or `ENV` (This will use the Environment/Runtime Plex URL) | N/A | ✅ | +| `timeout` | Plex Server Timeout | 60 | ❌ | +| `clean_bundles` | Runs Clean Bundles on the Server after all Metadata Files are run | false | ❌ | +| `empty_trash` | Runs Empty Trash on the Server after all Metadata Files are run | false | ❌ | +| `optimize` | Runs Optimize on the Server after all Metadata Files are run | false | ❌ | * **Do Not Use the Plex Token found in Plex's Preferences.xml file** diff --git a/docs/home/environmental.md b/docs/home/environmental.md index c1d95aba..b00cca11 100644 --- a/docs/home/environmental.md +++ b/docs/home/environmental.md @@ -33,6 +33,8 @@ These docs are assuming you have a basic understanding of Docker concepts. One | [No Missing](#no-missing) | `-nm` or `--no-missing` | `PMM_NO_MISSING` | | [No Report](#no-report) | `-nr` or `--no-report` | `PMM_NO_REPORT` | | [Read Only Config](#read-only-config) | `-ro` or `--read-only-config` | `PMM_READ_ONLY_CONFIG` | +| [ENV Plex URL](#env-plex-url--token) | `-pu` or `--plex-url` | `PMM_PLEX_URL` | +| [ENV Plex Token](#env-plex-url--token) | `-pt` or `--plex-token` | `PMM_PLEX_TOKEN` | | [Divider Character](#divider-character--screen-width) | `-d` or `--divider` | `PMM_DIVIDER` | | [Screen Width](#divider-character--screen-width) | `-w` or `--width` | `PMM_WIDTH` | @@ -905,6 +907,62 @@ docker run -it -v "X:\Media\Plex Meta Manager\config:/config:rw" meisnate12/plex ``` ```` +### ENV Plex URL & Token + +Replaces `ENV` when it is used plex `url` or `token`. + +#### Plex URL + + + + + + + + + + + + + + + + + +
ShellEnvironment
Flags-pu or --plex-urlPMM_PLEX_URL
Example--plex-url 192.168.1.12:32400PMM_PLEX_URL=192.168.1.12:32400
+ +#### Plex Token + + + + + + + + + + + + + + + + + +
ShellEnvironment
Flags-pt or --plex-tokenPMM_PLEX_TOKEN
Example--plex-token AB23HE4588PMM_PLEX_TOKEN=AB23HE4588
+ +````{tab} Local Environment +``` +python plex_meta_manager.py --plex-url 192.168.1.12:32400 --plex-token AB23HE4588 +``` +```` +````{tab} Docker Environment +``` +docker run -it -v "X:\Media\Plex Meta Manager\config:/config:rw" meisnate12/plex-meta-manager --plex-url 192.168.1.12:32400 --plex-token AB23HE4588 +``` +```` + + ### Divider Character & Screen Width Change the terminal output divider character or width. diff --git a/modules/config.py b/modules/config.py index 7cbcded8..ba82ea84 100644 --- a/modules/config.py +++ b/modules/config.py @@ -125,6 +125,8 @@ class ConfigFile: self.collection_only = attrs["collection_only"] if "collection_only" in attrs else False self.operations_only = attrs["operations_only"] if "operations_only" in attrs else False self.overlays_only = attrs["overlays_only"] if "overlays_only" in attrs else False + self.env_plex_url = attrs["plex_url"] if "plex_url" in attrs else "" + self.env_plex_token = attrs["plex_token"] if "plex_token" in attrs else "" current_time = datetime.now() with open(self.config_path, encoding="utf-8") as fp: @@ -854,6 +856,10 @@ class ConfigFile: "empty_trash": check_for_attribute(lib, "empty_trash", parent="plex", var_type="bool", default=self.general["plex"]["empty_trash"], save=False), "optimize": check_for_attribute(lib, "optimize", parent="plex", var_type="bool", default=self.general["plex"]["optimize"], save=False) } + if params["plex"]["url"].lower() == "env": + params["plex"]["url"] = self.env_plex_url + if params["plex"]["token"].lower() == "env": + params["plex"]["token"] = self.env_plex_token library = Plex(self, params) logger.info("") logger.info(f"{display_name} Library Connection Successful") diff --git a/plex_meta_manager.py b/plex_meta_manager.py index 183cecbf..a3f62e13 100644 --- a/plex_meta_manager.py +++ b/plex_meta_manager.py @@ -43,6 +43,8 @@ parser.add_argument("-nc", "--no-countdown", dest="no_countdown", help="Run with parser.add_argument("-nm", "--no-missing", dest="no_missing", help="Run without running the missing section", action="store_true", default=False) parser.add_argument("-nr", "--no-report", dest="no_report", help="Run without saving a report", action="store_true", default=False) parser.add_argument("-ro", "--read-only-config", dest="read_only_config", help="Run without writing to the config", action="store_true", default=False) +parser.add_argument("-pu", "--plex-url", dest="plex_url", help="Plex URL for Plex ENV URLs", default="", type=str) +parser.add_argument("-pt", "--plex-token", dest="plex_token", help="Plex Token for Plex ENV Tokens", default="", type=str) parser.add_argument("-d", "--divider", dest="divider", help="Character that divides the sections (Default: '=')", default="=", type=str) parser.add_argument("-w", "--width", dest="width", help="Screen Width (Default: 100)", default=100, type=int) args = parser.parse_args() @@ -100,6 +102,8 @@ 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) +plex_url = get_arg("PMM_PLEX_URL", args.plex_url) +plex_token = get_arg("PMM_PLEX_TOKEN", args.plex_token) if collections: collection_only = True @@ -207,6 +211,8 @@ def start(attrs): attrs["playlist_only"] = playlist_only attrs["operations_only"] = operations_only attrs["overlays_only"] = overlays_only + attrs["plex_url"] = plex_url + attrs["plex_token"] = plex_token logger.separator(debug=True) logger.debug(f"Run Command: {run_arg}") logger.debug(f"--config (PMM_CONFIG): {config_file}") @@ -231,6 +237,8 @@ def start(attrs): logger.debug(f"--no-missing (PMM_NO_MISSING): {no_missing}") logger.debug(f"--no-report (PMM_NO_REPORT): {no_report}") logger.debug(f"--read-only-config (PMM_READ_ONLY_CONFIG): {read_only_config}") + logger.debug(f"--plex-url (PMM_PLEX_URL): {plex_url}") + logger.debug(f"--plex-token (PMM_PLEX_TOKEN): {plex_token}") logger.debug(f"--divider (PMM_DIVIDER): {divider}") logger.debug(f"--width (PMM_WIDTH): {screen_width}") logger.debug(f"--debug (PMM_DEBUG): {debug}")