From 5ec22f344cb48c9f05920c97bab73f9f4d147b69 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Thu, 21 Apr 2022 01:35:07 -0400 Subject: [PATCH] [18] asset_directory per metadata_file --- VERSION | 2 +- modules/builder.py | 12 +++++++----- modules/config.py | 9 +++------ modules/library.py | 8 ++++---- modules/meta.py | 17 +++++++++-------- modules/plex.py | 12 ++++++++---- modules/util.py | 9 ++++++--- 7 files changed, 38 insertions(+), 31 deletions(-) diff --git a/VERSION b/VERSION index 1705867e..7475e292 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.16.5-develop17 +1.16.5-develop18 diff --git a/modules/builder.py b/modules/builder.py index f86a502e..fcb8cca4 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -223,6 +223,7 @@ class CollectionBuilder: self.libraries = [] self.playlist = library is None self.overlay = overlay + self.asset_directory = metadata.asset_directory if metadata.asset_directory else self.library.asset_directory methods = {m.lower(): m for m in self.data} if self.playlist: self.type = "playlist" @@ -276,7 +277,7 @@ class CollectionBuilder: if isinstance(data[methods["overlay"]], dict): if "name" not in data[methods["overlay"]] or not data[methods["overlay"]]["name"]: raise Failed(f"{self.Type} Error: overlay must have the name attribute") - self.overlay = data[methods["overlay"]]["name"] + self.overlay = str(data[methods["overlay"]]["name"]) if "git" in data[methods["overlay"]] and data[methods["overlay"]]["git"]: url = f"{util.github_base}{data[methods['overlay']]['git']}.png" elif "repo" in data[methods["overlay"]] and data[methods["overlay"]]["repo"]: @@ -303,9 +304,9 @@ class CollectionBuilder: while util.is_locked(overlay_path): time.sleep(1) else: - self.overlay = data[methods["overlay"]] + self.overlay = str(data[methods["overlay"]]) else: - self.overlay = self.mapping_name + self.overlay = str(self.mapping_name) logger.warning(f"{self.Type} Warning: No overlay attribute using mapping name {self.mapping_name} as the overlay name") if self.overlay.startswith("blur"): try: @@ -2407,7 +2408,8 @@ class CollectionBuilder: rating_keys.remove(int(item.ratingKey)) if overlay is not None: try: - self.library.update_asset(item, overlay=overlay, folders=self.details["asset_folders"], create=self.details["create_asset_folders"]) + self.library.update_asset(item, overlay=overlay, folders=self.details["asset_folders"], + create=self.details["create_asset_folders"], asset_directory=self.asset_directory) except Failed as e: logger.error(e) self.library.edit_tags("label", item, add_tags=add_tags, remove_tags=remove_tags, sync_tags=sync_tags) @@ -2606,7 +2608,7 @@ class CollectionBuilder: poster_image = None background_image = None asset_location = None - if self.library.asset_directory: + if self.asset_directory: name_mapping = self.name if "name_mapping" in self.details: if self.details["name_mapping"]: name_mapping = self.details["name_mapping"] diff --git a/modules/config.py b/modules/config.py index b7d9bb77..0e974daf 100644 --- a/modules/config.py +++ b/modules/config.py @@ -289,7 +289,7 @@ class ConfigFile: self.general = { "cache": check_for_attribute(self.data, "cache", parent="settings", var_type="bool", default=True), "cache_expiration": check_for_attribute(self.data, "cache_expiration", parent="settings", var_type="int", default=60), - "asset_directory": check_for_attribute(self.data, "asset_directory", parent="settings", var_type="list_path", default=[os.path.join(default_dir, "assets")], default_is_none=True), + "asset_directory": check_for_attribute(self.data, "asset_directory", parent="settings", var_type="list_path", default_is_none=True), "asset_folders": check_for_attribute(self.data, "asset_folders", parent="settings", var_type="bool", default=True), "asset_depth": check_for_attribute(self.data, "asset_depth", parent="settings", var_type="int", default=0), "create_asset_folders": check_for_attribute(self.data, "create_asset_folders", parent="settings", var_type="bool", default=False), @@ -487,9 +487,9 @@ class ConfigFile: files = util.load_files(paths_to_check, "playlist_files") if not files: raise Failed("Config Error: No Paths Found for playlist_files") - for file_type, playlist_file, temp_vars in files: + for file_type, playlist_file, temp_vars, asset_directory in files: try: - playlist_obj = PlaylistFile(self, file_type, playlist_file, temp_vars) + playlist_obj = PlaylistFile(self, file_type, playlist_file, temp_vars, asset_directory) self.playlist_names.extend([p for p in playlist_obj.playlists]) self.playlist_files.append(playlist_obj) except Failed as e: @@ -586,9 +586,6 @@ class ConfigFile: logger.info("") params["asset_directory"] = check_for_attribute(lib, "asset_directory", parent="settings", var_type="list_path", default=self.general["asset_directory"], default_is_none=True, save=False) - if params["asset_directory"] is None: - logger.warning("Config Warning: Assets will not be used asset_directory attribute must be set under config or under this specific Library") - params["asset_folders"] = check_for_attribute(lib, "asset_folders", parent="settings", var_type="bool", default=self.general["asset_folders"], do_print=False, save=False) params["asset_depth"] = check_for_attribute(lib, "asset_depth", parent="settings", var_type="int", default=self.general["asset_depth"], do_print=False, save=False) params["sync_mode"] = check_for_attribute(lib, "sync_mode", parent="settings", test_list=sync_modes, default=self.general["sync_mode"], do_print=False, save=False) diff --git a/modules/library.py b/modules/library.py index f6e6a017..4cfad716 100644 --- a/modules/library.py +++ b/modules/library.py @@ -121,9 +121,9 @@ class Library(ABC): logger.info(output) def scan_files(self): - for file_type, metadata_file, temp_vars in self.metadata_path: + for file_type, metadata_file, temp_vars, asset_directory in self.metadata_path: try: - meta_obj = MetadataFile(self.config, self, file_type, metadata_file, temp_vars) + meta_obj = MetadataFile(self.config, self, file_type, metadata_file, temp_vars, asset_directory) if meta_obj.collections: self.collections.extend([c for c in meta_obj.collections]) if meta_obj.metadata: @@ -131,9 +131,9 @@ class Library(ABC): self.metadata_files.append(meta_obj) except Failed as e: logger.error(e) - for file_type, overlay_file, temp_vars in self.overlay_path: + for file_type, overlay_file, temp_vars, asset_directory in self.overlay_path: try: - over_obj = OverlayFile(self.config, self, file_type, overlay_file, temp_vars) + over_obj = OverlayFile(self.config, self, file_type, overlay_file, temp_vars, asset_directory) self.overlays.extend([o.lower() for o in over_obj.overlays]) self.overlay_files.append(over_obj) except Failed as e: diff --git a/modules/meta.py b/modules/meta.py index 86ef772b..40a7f8c2 100644 --- a/modules/meta.py +++ b/modules/meta.py @@ -58,12 +58,13 @@ def get_dict(attribute, attr_data, check_list=None, lower=False): class DataFile: - def __init__(self, config, file_type, path, temp_vars): + def __init__(self, config, file_type, path, temp_vars, asset_directory): self.config = config self.library = None self.type = file_type self.path = path self.temp_vars = temp_vars + self.asset_directory = asset_directory self.data_type = "" self.templates = {} @@ -242,7 +243,7 @@ class DataFile: files = util.load_files(data["external_templates"], "external_templates") if not files: logger.error("Config Error: No Paths Found for external_templates") - for file_type, template_file, temp_vars in util.load_files(data["external_templates"], "external_templates"): + for file_type, template_file, temp_vars, _ in files: temp_data = self.load_file(file_type, template_file) if temp_data and isinstance(temp_data, dict) and "templates" in temp_data and temp_data["templates"] and isinstance(temp_data["templates"], dict): for temp_key, temp_value in temp_data["templates"].items(): @@ -253,8 +254,8 @@ class DataFile: self.temp_vars[tk] = tv class MetadataFile(DataFile): - def __init__(self, config, library, file_type, path, temp_vars): - super().__init__(config, file_type, path, temp_vars) + def __init__(self, config, library, file_type, path, temp_vars, asset_directory): + super().__init__(config, file_type, path, temp_vars, asset_directory) self.data_type = "Collection" self.library = library if file_type == "Data": @@ -1093,8 +1094,8 @@ class MetadataFile(DataFile): class PlaylistFile(DataFile): - def __init__(self, config, file_type, path, temp_vars): - super().__init__(config, file_type, path, temp_vars) + def __init__(self, config, file_type, path, temp_vars, asset_directory): + super().__init__(config, file_type, path, temp_vars, asset_directory) self.data_type = "Playlist" logger.info("") logger.info(f"Loading Playlist File {file_type}: {path}") @@ -1107,8 +1108,8 @@ class PlaylistFile(DataFile): logger.info(f"Playlist File Loaded Successfully") class OverlayFile(DataFile): - def __init__(self, config, library, file_type, path, temp_vars): - super().__init__(config, file_type, path, temp_vars) + def __init__(self, config, library, file_type, path, temp_vars, asset_directory): + super().__init__(config, file_type, path, temp_vars, asset_directory) self.library = library self.data_type = "Overlay" logger.info("") diff --git a/modules/plex.py b/modules/plex.py index acc79dfd..d8a50cad 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -806,7 +806,7 @@ class Plex(Library): logger.info(final) return final - def update_asset(self, item, overlay=None, folders=None, create=None): + def update_asset(self, item, overlay=None, folders=None, create=None, asset_directory=None): if isinstance(item, (Movie, Artist, Show, Episode, Season)): starting = item.show() if isinstance(item, (Episode, Season)) else item path_test = str(starting.locations[0]) @@ -821,6 +821,8 @@ class Plex(Library): folders = self.asset_folders if create is None: create = self.create_asset_folders + if asset_directory is None: + asset_directory = self.asset_directory poster, background, item_dir = self.find_assets( name="poster" if folders else name, @@ -910,7 +912,7 @@ class Plex(Library): self.upload_images(item, overlay=overlay) if create and folders and item_dir is None: filename, _ = util.validate_filename(name) - item_dir = os.path.join(self.asset_directory[0], filename) + item_dir = os.path.join(asset_directory[0], filename) os.makedirs(item_dir, exist_ok=True) logger.info(f"Asset Directory Created: {item_dir}") elif isinstance(item, (Movie, Show)) and not overlay and folders and item_dir is None: @@ -919,7 +921,7 @@ class Plex(Library): logger.warning(f"Asset Warning: No poster or background found in an assets folder for '{name}'") return None, None, item_dir - def update_asset2(self, item, folders=None, create=None): + def update_asset2(self, item, folders=None, create=None, asset_directory=None): if isinstance(item, (Movie, Artist, Show)): starting = item.show() if isinstance(item, (Episode, Season)) else item path_test = str(starting.locations[0]) @@ -934,6 +936,8 @@ class Plex(Library): folders = self.asset_folders if create is None: create = self.create_asset_folders + if asset_directory is None: + asset_directory = self.asset_directory poster, background, item_dir = self.find_assets( name="poster" if folders else name, @@ -1021,7 +1025,7 @@ class Plex(Library): if create and folders and item_dir is None: filename, _ = util.validate_filename(name) - item_dir = os.path.join(self.asset_directory[0], filename) + item_dir = os.path.join(asset_directory[0], filename) os.makedirs(item_dir, exist_ok=True) logger.info(f"Asset Directory Created: {item_dir}") elif folders and item_dir is None: diff --git a/modules/util.py b/modules/util.py index cb51a7d8..00a3d680 100644 --- a/modules/util.py +++ b/modules/util.py @@ -285,11 +285,14 @@ def load_files(files_to_load, method, file_type="yml"): temp_vars = {} if "template_variables" in file and file["template_variables"] and isinstance(file["template_variables"], dict): temp_vars = file["template_variables"] + asset_directory = None + if "asset_directory" in file and file["asset_directory"] and os.path.exists(file["asset_directory"]): + asset_directory = file["asset_directory"] def check_dict(attr, name): if attr in file: if file[attr]: - files.append((name, file[attr], temp_vars)) + files.append((name, file[attr], temp_vars, asset_directory)) else: logger.error(f"Config Error: {method} {attr} is blank") @@ -305,12 +308,12 @@ def load_files(files_to_load, method, file_type="yml"): else: yml_files = glob_filter(os.path.join(file["folder"], f"*.{file_type}")) if yml_files: - files.extend([("File", yml, temp_vars) for yml in yml_files]) + files.extend([("File", yml, temp_vars, asset_directory) for yml in yml_files]) else: logger.error(f"Config Error: No {file_type.upper()} (.{file_type}) files found in {file['folder']}") else: if os.path.exists(file): - files.append(("File", file, {})) + files.append(("File", file, {}, None)) else: logger.error(f"Config Error: Path not found: {file}") return files