[18] asset_directory per metadata_file

pull/858/head
meisnate12 3 years ago
parent c523492b87
commit 5ec22f344c

@ -1 +1 @@
1.16.5-develop17 1.16.5-develop18

@ -223,6 +223,7 @@ class CollectionBuilder:
self.libraries = [] self.libraries = []
self.playlist = library is None self.playlist = library is None
self.overlay = overlay 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} methods = {m.lower(): m for m in self.data}
if self.playlist: if self.playlist:
self.type = "playlist" self.type = "playlist"
@ -276,7 +277,7 @@ class CollectionBuilder:
if isinstance(data[methods["overlay"]], dict): if isinstance(data[methods["overlay"]], dict):
if "name" not in data[methods["overlay"]] or not data[methods["overlay"]]["name"]: 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") 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"]: if "git" in data[methods["overlay"]] and data[methods["overlay"]]["git"]:
url = f"{util.github_base}{data[methods['overlay']]['git']}.png" url = f"{util.github_base}{data[methods['overlay']]['git']}.png"
elif "repo" in data[methods["overlay"]] and data[methods["overlay"]]["repo"]: elif "repo" in data[methods["overlay"]] and data[methods["overlay"]]["repo"]:
@ -303,9 +304,9 @@ class CollectionBuilder:
while util.is_locked(overlay_path): while util.is_locked(overlay_path):
time.sleep(1) time.sleep(1)
else: else:
self.overlay = data[methods["overlay"]] self.overlay = str(data[methods["overlay"]])
else: 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") logger.warning(f"{self.Type} Warning: No overlay attribute using mapping name {self.mapping_name} as the overlay name")
if self.overlay.startswith("blur"): if self.overlay.startswith("blur"):
try: try:
@ -2407,7 +2408,8 @@ class CollectionBuilder:
rating_keys.remove(int(item.ratingKey)) rating_keys.remove(int(item.ratingKey))
if overlay is not None: if overlay is not None:
try: 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: except Failed as e:
logger.error(e) logger.error(e)
self.library.edit_tags("label", item, add_tags=add_tags, remove_tags=remove_tags, sync_tags=sync_tags) 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 poster_image = None
background_image = None background_image = None
asset_location = None asset_location = None
if self.library.asset_directory: if self.asset_directory:
name_mapping = self.name name_mapping = self.name
if "name_mapping" in self.details: if "name_mapping" in self.details:
if self.details["name_mapping"]: name_mapping = self.details["name_mapping"] if self.details["name_mapping"]: name_mapping = self.details["name_mapping"]

@ -289,7 +289,7 @@ class ConfigFile:
self.general = { self.general = {
"cache": check_for_attribute(self.data, "cache", parent="settings", var_type="bool", default=True), "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), "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_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), "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), "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") files = util.load_files(paths_to_check, "playlist_files")
if not files: if not files:
raise Failed("Config Error: No Paths Found for playlist_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: 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_names.extend([p for p in playlist_obj.playlists])
self.playlist_files.append(playlist_obj) self.playlist_files.append(playlist_obj)
except Failed as e: except Failed as e:
@ -586,9 +586,6 @@ class ConfigFile:
logger.info("") 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) 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_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["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) 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)

@ -121,9 +121,9 @@ class Library(ABC):
logger.info(output) logger.info(output)
def scan_files(self): 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: 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: if meta_obj.collections:
self.collections.extend([c for c in meta_obj.collections]) self.collections.extend([c for c in meta_obj.collections])
if meta_obj.metadata: if meta_obj.metadata:
@ -131,9 +131,9 @@ class Library(ABC):
self.metadata_files.append(meta_obj) self.metadata_files.append(meta_obj)
except Failed as e: except Failed as e:
logger.error(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: 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.overlays.extend([o.lower() for o in over_obj.overlays])
self.overlay_files.append(over_obj) self.overlay_files.append(over_obj)
except Failed as e: except Failed as e:

@ -58,12 +58,13 @@ def get_dict(attribute, attr_data, check_list=None, lower=False):
class DataFile: 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.config = config
self.library = None self.library = None
self.type = file_type self.type = file_type
self.path = path self.path = path
self.temp_vars = temp_vars self.temp_vars = temp_vars
self.asset_directory = asset_directory
self.data_type = "" self.data_type = ""
self.templates = {} self.templates = {}
@ -242,7 +243,7 @@ class DataFile:
files = util.load_files(data["external_templates"], "external_templates") files = util.load_files(data["external_templates"], "external_templates")
if not files: if not files:
logger.error("Config Error: No Paths Found for external_templates") 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) 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): 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(): for temp_key, temp_value in temp_data["templates"].items():
@ -253,8 +254,8 @@ class DataFile:
self.temp_vars[tk] = tv self.temp_vars[tk] = tv
class MetadataFile(DataFile): class MetadataFile(DataFile):
def __init__(self, config, library, 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) super().__init__(config, file_type, path, temp_vars, asset_directory)
self.data_type = "Collection" self.data_type = "Collection"
self.library = library self.library = library
if file_type == "Data": if file_type == "Data":
@ -1093,8 +1094,8 @@ class MetadataFile(DataFile):
class PlaylistFile(DataFile): class PlaylistFile(DataFile):
def __init__(self, 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) super().__init__(config, file_type, path, temp_vars, asset_directory)
self.data_type = "Playlist" self.data_type = "Playlist"
logger.info("") logger.info("")
logger.info(f"Loading Playlist File {file_type}: {path}") logger.info(f"Loading Playlist File {file_type}: {path}")
@ -1107,8 +1108,8 @@ class PlaylistFile(DataFile):
logger.info(f"Playlist File Loaded Successfully") logger.info(f"Playlist File Loaded Successfully")
class OverlayFile(DataFile): class OverlayFile(DataFile):
def __init__(self, config, library, 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) super().__init__(config, file_type, path, temp_vars, asset_directory)
self.library = library self.library = library
self.data_type = "Overlay" self.data_type = "Overlay"
logger.info("") logger.info("")

@ -806,7 +806,7 @@ class Plex(Library):
logger.info(final) logger.info(final)
return 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)): if isinstance(item, (Movie, Artist, Show, Episode, Season)):
starting = item.show() if isinstance(item, (Episode, Season)) else item starting = item.show() if isinstance(item, (Episode, Season)) else item
path_test = str(starting.locations[0]) path_test = str(starting.locations[0])
@ -821,6 +821,8 @@ class Plex(Library):
folders = self.asset_folders folders = self.asset_folders
if create is None: if create is None:
create = self.create_asset_folders create = self.create_asset_folders
if asset_directory is None:
asset_directory = self.asset_directory
poster, background, item_dir = self.find_assets( poster, background, item_dir = self.find_assets(
name="poster" if folders else name, name="poster" if folders else name,
@ -910,7 +912,7 @@ class Plex(Library):
self.upload_images(item, overlay=overlay) self.upload_images(item, overlay=overlay)
if create and folders and item_dir is None: if create and folders and item_dir is None:
filename, _ = util.validate_filename(name) 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) os.makedirs(item_dir, exist_ok=True)
logger.info(f"Asset Directory Created: {item_dir}") logger.info(f"Asset Directory Created: {item_dir}")
elif isinstance(item, (Movie, Show)) and not overlay and folders and item_dir is None: 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}'") logger.warning(f"Asset Warning: No poster or background found in an assets folder for '{name}'")
return None, None, item_dir 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)): if isinstance(item, (Movie, Artist, Show)):
starting = item.show() if isinstance(item, (Episode, Season)) else item starting = item.show() if isinstance(item, (Episode, Season)) else item
path_test = str(starting.locations[0]) path_test = str(starting.locations[0])
@ -934,6 +936,8 @@ class Plex(Library):
folders = self.asset_folders folders = self.asset_folders
if create is None: if create is None:
create = self.create_asset_folders create = self.create_asset_folders
if asset_directory is None:
asset_directory = self.asset_directory
poster, background, item_dir = self.find_assets( poster, background, item_dir = self.find_assets(
name="poster" if folders else name, name="poster" if folders else name,
@ -1021,7 +1025,7 @@ class Plex(Library):
if create and folders and item_dir is None: if create and folders and item_dir is None:
filename, _ = util.validate_filename(name) 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) os.makedirs(item_dir, exist_ok=True)
logger.info(f"Asset Directory Created: {item_dir}") logger.info(f"Asset Directory Created: {item_dir}")
elif folders and item_dir is None: elif folders and item_dir is None:

@ -285,11 +285,14 @@ def load_files(files_to_load, method, file_type="yml"):
temp_vars = {} temp_vars = {}
if "template_variables" in file and file["template_variables"] and isinstance(file["template_variables"], dict): if "template_variables" in file and file["template_variables"] and isinstance(file["template_variables"], dict):
temp_vars = file["template_variables"] 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): def check_dict(attr, name):
if attr in file: if attr in file:
if file[attr]: if file[attr]:
files.append((name, file[attr], temp_vars)) files.append((name, file[attr], temp_vars, asset_directory))
else: else:
logger.error(f"Config Error: {method} {attr} is blank") logger.error(f"Config Error: {method} {attr} is blank")
@ -305,12 +308,12 @@ def load_files(files_to_load, method, file_type="yml"):
else: else:
yml_files = glob_filter(os.path.join(file["folder"], f"*.{file_type}")) yml_files = glob_filter(os.path.join(file["folder"], f"*.{file_type}"))
if yml_files: 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: else:
logger.error(f"Config Error: No {file_type.upper()} (.{file_type}) files found in {file['folder']}") logger.error(f"Config Error: No {file_type.upper()} (.{file_type}) files found in {file['folder']}")
else: else:
if os.path.exists(file): if os.path.exists(file):
files.append(("File", file, {})) files.append(("File", file, {}, None))
else: else:
logger.error(f"Config Error: Path not found: {file}") logger.error(f"Config Error: Path not found: {file}")
return files return files

Loading…
Cancel
Save