fixes for multiple metadata

pull/240/head
meisnate12 4 years ago
parent e9a18c23cc
commit fe47de73b7

@ -173,9 +173,10 @@ def split_attribute(text):
return attribute, modifier, final
class CollectionBuilder:
def __init__(self, config, library, name, data):
def __init__(self, config, library, metadata, name, data):
self.config = config
self.library = library
self.metadata = metadata
self.name = name
self.data = data
self.details = {
@ -203,7 +204,7 @@ class CollectionBuilder:
methods = {m.lower(): m for m in self.data}
if "template" in methods:
if not self.library.templates:
if not self.metadata.templates:
raise Failed("Collection Error: No templates found")
elif not self.data[methods["template"]]:
raise Failed("Collection Error: template attribute is blank")
@ -215,9 +216,9 @@ class CollectionBuilder:
raise Failed("Collection Error: template sub-attribute name is required")
elif not data_template["name"]:
raise Failed("Collection Error: template sub-attribute name is blank")
elif data_template["name"] not in self.library.templates:
elif data_template["name"] not in self.metadata.templates:
raise Failed(f"Collection Error: template {data_template['name']} not found")
elif not isinstance(self.library.templates[data_template["name"]], dict):
elif not isinstance(self.metadata.templates[data_template["name"]], dict):
raise Failed(f"Collection Error: template {data_template['name']} is not a dictionary")
else:
for tm in data_template:
@ -225,7 +226,7 @@ class CollectionBuilder:
raise Failed(f"Collection Error: template sub-attribute {tm} is blank")
template_name = data_template["name"]
template = self.library.templates[template_name]
template = self.metadata.templates[template_name]
default = {}
if "default" in template:
@ -526,7 +527,7 @@ class CollectionBuilder:
final_tmdb_values = util.get_list(smart_data, split=False)
else:
final_tmdb_values = util.get_list(smart_data)
results_list = self.library.validate_search_list(final_tmdb_values, smart, fail=True, title=False, pairs=True)
results_list = self.library.validate_search_list(final_tmdb_values, smart, title=False, pairs=True)
elif smart in ["decade", "year", "episode_year"] and smart_mod in ["", ".not"]:
results_list = [(y, y) for y in util.get_year_list(smart_data, current_year, smart_final)]
else:

@ -593,7 +593,7 @@ class Config:
logger.info("")
try:
builder = CollectionBuilder(self, library, mapping_name, collection_attrs)
builder = CollectionBuilder(self, library, metadata, mapping_name, collection_attrs)
except Failed as f:
util.print_stacktrace()
util.print_multiline(f, error=True)

@ -35,10 +35,12 @@ class Metadata:
logger.warning(f"Config Warning: {attribute} attribute is blank")
return None
try:
if file_type == "URL":
content = requests.get(path).content
elif file_type == "Git":
content = requests.get(f"{self.github_base}{path}.yml").content
if file_type in ["URL", "Git"]:
content_path = path if file_type == "URL" else f"{self.github_base}{path}.yml"
response = requests.get(content_path)
if response.status_code >= 400:
raise Failed(f"URL Error: No file found at {content_path}")
content = response.content
elif os.path.exists(os.path.abspath(path)):
content = open(path, encoding="utf-8")
else:

@ -316,16 +316,20 @@ class PlexAPI:
for file_type, metadata_file in params["metadata_path"]:
try:
meta_obj = Metadata(self, file_type, metadata_file)
self.collections.extend([c for c in meta_obj.collections])
self.metadatas.extend([c for c in meta_obj.metadata])
if meta_obj.collections:
self.collections.extend([c for c in meta_obj.collections])
if meta_obj.metadata:
self.metadatas.extend([c for c in meta_obj.metadata])
self.metadata_files.append(meta_obj)
except Failed as e:
logger.error(e)
if len(self.metadata_files) == 0:
logger.info("")
raise Failed("Metadata File Error: No valid metadata files found")
if params["asset_directory"]:
logger.info("")
for ad in params["asset_directory"]:
logger.info(f"Using Asset Directory: {ad}")
@ -472,7 +476,7 @@ class PlexAPI:
smart_filter = self.get_collection(collection)._data.attrib.get('content')
return smart_filter[smart_filter.index("?"):]
def validate_search_list(self, data, search_name, fail=False, title=True, pairs=False):
def validate_search_list(self, data, search_name, title=True, pairs=False):
final_search = search_translation[search_name] if search_name in search_translation else search_name
search_choices = self.get_search_choices(final_search, title=title)
valid_list = []
@ -482,8 +486,6 @@ class PlexAPI:
valid_list.append((value, search_choices[str(value).lower()]))
else:
valid_list.append(search_choices[str(value).lower()])
elif fail:
raise Failed(f"Plex Error: {search_name}: {value} not found")
else:
logger.error(f"Plex Error: {search_name}: {value} not found")
return valid_list

Loading…
Cancel
Save