From aa95c63794f67d89e606f651b544d592912a2f24 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Sat, 18 Dec 2021 20:12:04 -0500 Subject: [PATCH] added dictionary_variables to tmdb_collections --- modules/config.py | 14 +++++++++++++- plex_meta_manager.py | 28 ++++++++++++++-------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/modules/config.py b/modules/config.py index 3d156765..ddee274c 100644 --- a/modules/config.py +++ b/modules/config.py @@ -559,10 +559,22 @@ class ConfigFile: if "sonarr_remove_by_tag" in lib["operations"]: params["sonarr_remove_by_tag"] = check_for_attribute(lib["operations"], "sonarr_remove_by_tag", var_type="comma_list", default=False, save=False) if "tmdb_collections" in lib["operations"]: - params["tmdb_collections"] = {"exclude_ids": [], "remove_suffix": None, "template": {"tmdb_collection_details": "<>"}} + params["tmdb_collections"] = { + "exclude_ids": [], + "remove_suffix": None, + "dictionary_variables": {}, + "template": {"tmdb_collection_details": "<>"} + } if lib["operations"]["tmdb_collections"] and isinstance(lib["operations"]["tmdb_collections"], dict): + params["tmdb_collections"]["exclude_ids"] = check_for_attribute(lib["operations"]["tmdb_collections"], "exclude_ids", var_type="int_list", default_is_none=True, save=False) params["tmdb_collections"]["remove_suffix"] = check_for_attribute(lib["operations"]["tmdb_collections"], "remove_suffix", default_is_none=True, save=False) + if "dictionary_variables" in lib["operations"]["tmdb_collections"] and lib["operations"]["tmdb_collections"]["dictionary_variables"] and isinstance(lib["operations"]["tmdb_collections"]["dictionary_variables"], dict): + for key, value in lib["operations"]["tmdb_collections"]["dictionary_variables"].items(): + if isinstance(value, dict): + params["tmdb_collections"]["dictionary_variables"][key] = value + else: + logger.warning(f"Config Warning: tmdb_collections dictionary_variables {key} must be a dictionary") if "template" in lib["operations"]["tmdb_collections"] and lib["operations"]["tmdb_collections"]["template"] and isinstance(lib["operations"]["tmdb_collections"]["template"], dict): params["tmdb_collections"]["template"] = lib["operations"]["tmdb_collections"]["template"] else: diff --git a/plex_meta_manager.py b/plex_meta_manager.py index ca18a372..ab7baa71 100644 --- a/plex_meta_manager.py +++ b/plex_meta_manager.py @@ -846,21 +846,21 @@ def library_operations(config, library): util.separator(f"Starting TMDb Collections") logger.info("") suffixes = util.get_list(library.tmdb_collections["remove_suffix"]) - def remove_suffixes(_name): - if suffixes: - for suffix in suffixes: - if _name.endswith(suffix): - _name = _name[:-len(_name)] - return _name.strip() - + new_collections = {} + for _i, _n in tmdb_collections.items(): + if int(_i) not in library.tmdb_collections["exclude_ids"]: + template = {"name": "TMDb Collection", "collection_id": _i} + for k, v in library.tmdb_collections["dictionary_variables"]: + if int(_i) in v: + template[k] = v[int(_i)] + if suffixes: + for suffix in suffixes: + if _n.endswith(suffix): + _n = _n[:-len(_n)] + new_collections[_n.strip()] = {"template": template} metadata = MetadataFile(config, library, "Data", { - "collections": { - remove_suffixes(_n): {"template": {"name": "TMDb Collection", "collection_id": _i}} - for _i, _n in tmdb_collections.items() if int(_i) not in library.tmdb_collections["exclude_ids"] - }, - "templates": { - "TMDb Collection": library.tmdb_collections["template"] - } + "collections": new_collections, + "templates": {"TMDb Collection": library.tmdb_collections["template"]} }) run_collection(config, library, metadata, metadata.get_collections(None))