diff --git a/VERSION b/VERSION index 2efa8bca..e25c3141 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.16.3-develop15 +1.16.3-develop16 diff --git a/modules/config.py b/modules/config.py index 9e06c93f..3fb5c639 100644 --- a/modules/config.py +++ b/modules/config.py @@ -479,67 +479,23 @@ class ConfigFile: self.playlist_names = [] self.playlist_files = [] - playlists_pairs = [] if "playlist_files" in self.data: logger.info("Reading in Playlist Files") - if self.data["playlist_files"] is None: + if self.data["playlist_files"]: + paths_to_check = self.data["playlist_files"] + else: default_playlist_file = os.path.abspath(os.path.join(self.default_dir, "playlists.yml")) logger.warning(f"Config Warning: playlist_files attribute is blank using default: {default_playlist_file}") paths_to_check = [default_playlist_file] - elif isinstance(self.data["playlist_files"], list): - paths_to_check = self.data["playlist_files"] - else: - paths_to_check = [self.data["playlist_files"]] - for path in paths_to_check: - if isinstance(path, dict): - temp_vars = {} - if "template_variables" in path and path["template_variables"] and isinstance(path["template_variables"], dict): - temp_vars = path["template_variables"] - def check_dict(attr): - if attr in path: - if path[attr] is None: - err = f"Config Error: playlist_files {attr} is blank" - self.errors.append(err) - logger.error(err) - else: - return path[attr] - - url = check_dict("url") - if url: - playlists_pairs.append(("URL", url, temp_vars)) - git = check_dict("git") - if git: - playlists_pairs.append(("Git", git, temp_vars)) - repo = check_dict("repo") - if repo: - playlists_pairs.append(("Repo", repo, temp_vars)) - file = check_dict("file") - if file: - playlists_pairs.append(("File", file, temp_vars)) - folder = check_dict("folder") - if folder: - if os.path.isdir(folder): - yml_files = util.glob_filter(os.path.join(folder, "*.yml")) - if yml_files: - playlists_pairs.extend([("File", yml, temp_vars) for yml in yml_files]) - else: - logger.error(f"Config Error: No YAML (.yml) files found in {folder}") - else: - logger.error(f"Config Error: Folder not found: {folder}") - else: - if os.path.exists(path): - playlists_pairs.append(("File", path, {})) - else: - logger.warning(f"Config Warning: Path not found: {path}") + for file_type, playlist_file, temp_vars in util.load_yaml_files(paths_to_check): + try: + playlist_obj = PlaylistFile(self, file_type, playlist_file, temp_vars) + self.playlist_names.extend([p for p in playlist_obj.playlists]) + self.playlist_files.append(playlist_obj) + except Failed as e: + logger.error(e) else: logger.warning("playlist_files attribute not found") - for file_type, playlist_file, temp_vars in playlists_pairs: - try: - playlist_obj = PlaylistFile(self, file_type, playlist_file, temp_vars) - self.playlist_names.extend([p for p in playlist_obj.playlists]) - self.playlist_files.append(playlist_obj) - except Failed as e: - logger.error(e) self.TVDb = TVDb(self, self.general["tvdb_language"]) self.IMDb = IMDb(self) @@ -821,30 +777,9 @@ class ConfigFile: try: if lib and "metadata_path" in lib: - params["metadata_path"] = [] - if lib["metadata_path"] is None: + if not lib["metadata_path"]: raise Failed("Config Error: metadata_path attribute is blank") - paths_to_check = lib["metadata_path"] if isinstance(lib["metadata_path"], list) else [lib["metadata_path"]] - for path in paths_to_check: - if isinstance(path, dict): - temp_vars = {} - if "template_variables" in path and path["template_variables"] and isinstance(path["template_variables"], dict): - temp_vars = path["template_variables"] - def check_dict(attr, name): - if attr in path: - if path[attr] is None: - err = f"Config Error: metadata_path {attr} is blank" - self.errors.append(err) - logger.error(err) - else: - params["metadata_path"].append((name, path[attr], temp_vars)) - check_dict("url", "URL") - check_dict("git", "Git") - check_dict("repo", "Repo") - check_dict("file", "File") - check_dict("folder", "Folder") - else: - params["metadata_path"].append(("File", path, {})) + params["metadata_path"] = util.load_yaml_files(lib["metadata_path"]) else: params["metadata_path"] = [("File", os.path.join(default_dir, f"{library_name}.yml"), {})] params["default_dir"] = default_dir diff --git a/modules/meta.py b/modules/meta.py index b56f5c0f..a7c06c05 100644 --- a/modules/meta.py +++ b/modules/meta.py @@ -237,36 +237,7 @@ class DataFile: def load_templates(self): if "load_templates" in self.templates and self.templates["load_templates"]: - template_files = [] - for template_file in util.get_list(self.templates["load_templates"], split=False): - if isinstance(template_file, dict): - temp_vars = {} - if "template_variables" in template_file and template_file["template_variables"] and isinstance(template_file["template_variables"], dict): - temp_vars = template_file["template_variables"] - def check_dict(attr, name): - if attr in template_file: - if template_file[attr] is None: - logger.error(f"Config Error: metadata_path {attr} is blank") - else: - template_files.append((name, template_file[attr], temp_vars)) - check_dict("url", "URL") - check_dict("git", "Git") - check_dict("repo", "Repo") - check_dict("file", "File") - if "folder" in template_file: - if template_file["folder"] is None: - logger.error(f"Config Error: metadata_path folder is blank") - elif not os.path.isdir(template_file["folder"]): - logger.error(f"Config Error: Folder not found: {template_file['folder']}") - else: - yml_files = util.glob_filter(os.path.join(template_file["folder"], "*.yml")) - if yml_files: - template_files.extend([("File", yml, temp_vars) for yml in yml_files]) - else: - logger.error(f"Config Error: No YAML (.yml) files found in {template_file['folder']}") - else: - template_files.append(("File", template_file, {})) - for file_type, template_file, temp_vars in template_files: + for file_type, template_file, temp_vars in util.load_yaml_files(self.templates["load_templates"]): 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(): diff --git a/modules/util.py b/modules/util.py index de5dd64c..5301996a 100644 --- a/modules/util.py +++ b/modules/util.py @@ -257,6 +257,43 @@ def time_window(tw): else: return tw +def load_yaml_files(yaml_files): + files = [] + for yaml_file in get_list(yaml_files, split=False): + if isinstance(yaml_file, dict): + temp_vars = {} + if "template_variables" in yaml_file and yaml_file["template_variables"] and isinstance(yaml_file["template_variables"], dict): + temp_vars = yaml_file["template_variables"] + + def check_dict(attr, name): + if attr in yaml_file: + if yaml_file[attr]: + files.append((name, yaml_file[attr], temp_vars)) + else: + logger.error(f"Config Error: metadata_path {attr} is blank") + + check_dict("url", "URL") + check_dict("git", "Git") + check_dict("repo", "Repo") + check_dict("file", "File") + if "folder" in yaml_file: + if yaml_file["folder"] is None: + logger.error(f"Config Error: metadata_path folder is blank") + elif not os.path.isdir(yaml_file["folder"]): + logger.error(f"Config Error: Folder not found: {yaml_file['folder']}") + else: + yml_files = glob_filter(os.path.join(yaml_file["folder"], "*.yml")) + if yml_files: + files.extend([("File", yml, temp_vars) for yml in yml_files]) + else: + logger.error(f"Config Error: No YAML (.yml) files found in {yaml_file['folder']}") + else: + if os.path.exists(yaml_file): + files.append(("File", yaml_file, {})) + else: + logger.warning(f"Config Warning: Path not found: {path}") + return files + def check_num(num, is_int=True): try: return int(str(num)) if is_int else float(str(num))