From 3a655c6d5a7ed888960f3474a2cd734c1a94e370 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Wed, 1 Jun 2022 00:50:38 -0400 Subject: [PATCH] [10] library level template variables --- VERSION | 2 +- docs/config/libraries.md | 38 +++++++++++++++++++++++++------------- modules/config.py | 10 +++++++--- modules/operations.py | 20 ++++++++++---------- modules/util.py | 7 ++++++- 5 files changed, 49 insertions(+), 28 deletions(-) diff --git a/VERSION b/VERSION index f6edf455..ef126b24 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.17.0-develop9 +1.17.0-develop10 diff --git a/docs/config/libraries.md b/docs/config/libraries.md index b1baf0c1..46d74044 100644 --- a/docs/config/libraries.md +++ b/docs/config/libraries.md @@ -78,19 +78,20 @@ radarr: The available attributes for each library are as follows: -| Attribute | Values | Default | Required | -|:-------------------------------------------|:------------------------------------------------------------------------------------------------------|:-------------------------------------:|:-------------------------------:| -| [`library_name`](#library-name) | Library name (required only when trying to use multiple libraries with the same name) | Base Attribute Name | ❌ | -| [`metadata_path`](#metadata-path) | Location of Metadata YAML files | `/config/<>.yml` | ❌ | -| [`overlay_path`](#overlay-path) | Location of Overlay YAML files | None | ❌ | -| [`report_path`](#report-path) | Location to create the YAML file listing added, removed, filtered, and missing items for this library | `/config/<>_report.yml` | ❌ | -| [`schedule`](../metadata/details/schedule) | Use any [schedule option](../metadata/details/schedule) to control when this library is run. | daily | ❌ | -| [`operations`](operations) | Library Operations to run | N/A | ❌ | -| [`settings`](settings) | Any `setting` attribute that overrides a global value | global | ❌ | -| [`plex`](plex) | Any `plex` attribute that overrides a global value | global | ✅ Either here or globally | -| [`radarr`](radarr) | Any `radarr` attribute that overrides a global value | global | ❌ | -| [`sonarr`](sonarr) | Any `sonarr` attribute that overrides a global value | global | ❌ | -| [`tautulli`](tautulli) | Any `tautulli` attribute that overrides a global value | global | ❌ | +| Attribute | Values | Default | Required | +|:--------------------------------------------|:------------------------------------------------------------------------------------------------------|:-------------------------------------:|:-------------------------------:| +| [`library_name`](#library-name) | Library name (required only when trying to use multiple libraries with the same name) | Base Attribute Name | ❌ | +| [`metadata_path`](#metadata-path) | Location of Metadata YAML files | `/config/<>.yml` | ❌ | +| [`overlay_path`](#overlay-path) | Location of Overlay YAML files | None | ❌ | +| [`report_path`](#report-path) | Location to create the YAML file listing added, removed, filtered, and missing items for this library | `/config/<>_report.yml` | ❌ | +| [`template_variables`](#template-variables) | Library template variables to be applied to every Metadata and Overlay file run. | N/A | ❌ | +| [`schedule`](../metadata/details/schedule) | Use any [schedule option](../metadata/details/schedule) to control when this library is run. | daily | ❌ | +| [`operations`](operations) | Library Operations to run | N/A | ❌ | +| [`settings`](settings) | Any `setting` attribute that overrides a global value | global | ❌ | +| [`plex`](plex) | Any `plex` attribute that overrides a global value | global | ✅ Either here or globally | +| [`radarr`](radarr) | Any `radarr` attribute that overrides a global value | global | ❌ | +| [`sonarr`](sonarr) | Any `sonarr` attribute that overrides a global value | global | ❌ | +| [`tautulli`](tautulli) | Any `tautulli` attribute that overrides a global value | global | ❌ | ### Library Name @@ -189,6 +190,17 @@ libraries: report_path: /config/reports/Movies.yml ``` +### Template Variables + +Library template variables to be applied to every Metadata and Overlay file run. + +```yaml +libraries: + Movies: + template_variable: + collection_mode: true +``` + ## Playlist Files Attribute As playlists are not tied to one specific library and can combine media from multiple libraries, they require their own special [Playlist Files](../metadata/metadata) to work. diff --git a/modules/config.py b/modules/config.py index e3aaad96..6c85f2c0 100644 --- a/modules/config.py +++ b/modules/config.py @@ -730,16 +730,20 @@ class ConfigFile: if self.Trakt is None and params["mass_trakt_rating_update"]: error_check("mass_trakt_rating_update", "Trakt") + lib_vars = {} + if "template_variables" in lib and lib["template_variables"] and isinstance(lib["template_variables"], dict): + lib_vars = lib["template_variables"] + try: if lib and "metadata_path" in lib: if not lib["metadata_path"]: raise Failed("Config Error: metadata_path attribute is blank") - files = util.load_files(lib["metadata_path"], "metadata_path", schedule=(current_time, self.run_hour, self.ignore_schedules)) + files = util.load_files(lib["metadata_path"], "metadata_path", schedule=(current_time, self.run_hour, self.ignore_schedules), lib_vars=lib_vars) if not files: raise Failed("Config Error: No Paths Found for metadata_path") params["metadata_path"] = files elif os.path.exists(os.path.join(default_dir, f"{library_name}.yml")): - params["metadata_path"] = [("File", os.path.join(default_dir, f"{library_name}.yml"), {}, None)] + params["metadata_path"] = [("File", os.path.join(default_dir, f"{library_name}.yml"), lib_vars, None)] else: params["metadata_path"] = [] params["default_dir"] = default_dir @@ -761,7 +765,7 @@ class ConfigFile: try: if not lib["overlay_path"]: raise Failed("Config Error: overlay_path attribute is blank") - files = util.load_files(lib["overlay_path"], "overlay_path") + files = util.load_files(lib["overlay_path"], "overlay_path", lib_vars=lib_vars) if not files: raise Failed("Config Error: No Paths Found for overlay_path") for file in util.get_list(lib["overlay_path"], split=False): diff --git a/modules/operations.py b/modules/operations.py index f5eb1656..83b8a690 100644 --- a/modules/operations.py +++ b/modules/operations.py @@ -119,16 +119,16 @@ class Operations: batch_display += f"\n{self.library.edit_tags('label', item, add_tags=add_labels, remove_tags=remove_labels, do_print=False)}" except Failed: pass - - path = os.path.dirname(str(item.locations[0])) if self.library.is_movie else str(item.locations[0]) - if self.library.Radarr and self.library.radarr_add_all_existing and tmdb_id: - path = path.replace(self.library.Radarr.plex_path, self.library.Radarr.radarr_path) - path = path[:-1] if path.endswith(('/', '\\')) else path - radarr_adds.append((tmdb_id, path)) - if self.library.Sonarr and self.library.sonarr_add_all_existing and tvdb_id: - path = path.replace(self.library.Sonarr.plex_path, self.library.Sonarr.sonarr_path) - path = path[:-1] if path.endswith(("/", "\\")) else path - sonarr_adds.append((tvdb_id, path)) + if item.locations: + path = os.path.dirname(str(item.locations[0])) if self.library.is_movie else str(item.locations[0]) + if self.library.Radarr and self.library.radarr_add_all_existing and tmdb_id: + path = path.replace(self.library.Radarr.plex_path, self.library.Radarr.radarr_path) + path = path[:-1] if path.endswith(('/', '\\')) else path + radarr_adds.append((tmdb_id, path)) + if self.library.Sonarr and self.library.sonarr_add_all_existing and tvdb_id: + path = path.replace(self.library.Sonarr.plex_path, self.library.Sonarr.sonarr_path) + path = path[:-1] if path.endswith(("/", "\\")) else path + sonarr_adds.append((tvdb_id, path)) tmdb_item = None if any([o == "tmdb" for o in self.library.meta_operations]): diff --git a/modules/util.py b/modules/util.py index 502cab1c..e04249f2 100644 --- a/modules/util.py +++ b/modules/util.py @@ -380,13 +380,18 @@ def time_window(tw): else: return tw -def load_files(files_to_load, method, schedule=None): +def load_files(files_to_load, method, schedule=None, lib_vars=None): files = [] + if not lib_vars: + lib_vars = {} for file in get_list(files_to_load, split=False): if isinstance(file, dict): temp_vars = {} if "template_variables" in file and file["template_variables"] and isinstance(file["template_variables"], dict): temp_vars = file["template_variables"] + for k, v in lib_vars.items(): + if k not in temp_vars: + temp_vars[k] = v asset_directory = [] if "asset_directory" in file and file["asset_directory"]: for asset_path in get_list(file["asset_directory"], split=False):