[50] fix overlapping overlays

This commit is contained in:
meisnate12 2022-06-22 03:19:15 -04:00
parent ee49b42b15
commit b6c7677025
6 changed files with 36 additions and 34 deletions

View file

@ -1 +1 @@
1.17.0-develop49
1.17.0-develop50

View file

@ -260,7 +260,7 @@ class CollectionBuilder:
suppress = util.get_list(data[methods["suppress_overlays"]])
else:
logger.error(f"Overlay Error: suppress_overlays attribute is blank")
self.overlay = Overlay(config, library, overlay_data, suppress)
self.overlay = Overlay(config, library, self.mapping_name, overlay_data, suppress)
self.sync_to_users = None
self.valid_users = []
@ -1775,7 +1775,7 @@ class CollectionBuilder:
error = f"{self.Type} Error: {final_attr} {method} attribute does not work for music libraries"
elif not self.library.is_music and final_attr in plex.music_searches:
error = f"{self.Type} Error: {final_attr} {method} attribute only works for music libraries"
elif _data is not False and not _data:
elif _data is not False and _data != 0 and not _data:
error = f"{self.Type} Error: {final_attr} {method} attribute is blank"
else:
if final_attr.startswith(("any", "all")):

View file

@ -21,6 +21,7 @@ class Library(ABC):
self.queue_names = []
self.metadata_files = []
self.overlay_files = []
self.overlay_names = []
self.movie_map = {}
self.show_map = {}
self.imdb_map = {}
@ -144,6 +145,7 @@ class Library(ABC):
for file_type, overlay_file, temp_vars, asset_directory in self.overlay_path:
try:
overlay_obj = OverlayFile(self.config, self, file_type, overlay_file, temp_vars, asset_directory)
self.overlay_names.extend([p for p in overlay_obj.overlays])
self.overlay_files.append(overlay_obj)
self.queue_names.extend([q for q in overlay_obj.queues])
except Failed as e:

View file

@ -1195,7 +1195,7 @@ class OverlayFile(DataFile):
logger.info("")
logger.info(f"Loading Overlay {file_type}: {path}")
data = self.load_file(self.type, self.path)
self.overlays = get_dict("overlays", data)
self.overlays = get_dict("overlays", data, library.overlay_names)
self.templates = get_dict("templates", data)
self.queues = get_dict("queues", data, library.queue_names)
self.external_templates(data)

View file

@ -118,8 +118,9 @@ class Overlays:
if self.config.Cache:
for over_name in over_names:
if over_name in util.special_text_overlays:
rating_type = over_name[5:-1]
overlay = properties[over_name]
if overlay.name in util.special_text_overlays:
rating_type = overlay.name[5:-1]
if rating_type.endswith(("%", "#")):
rating_type = rating_type[:-1]
cache_rating = self.config.Cache.query_overlay_ratings(item.ratingKey, rating_type)
@ -132,7 +133,7 @@ class Overlays:
try:
poster, _, item_dir, name = self.library.find_item_assets(item)
if not poster and self.library.assets_for_all and self.library.show_missing_assets:
if self.config.asset_folders:
if self.library.asset_folders:
logger.warning(f"Asset Warning: No poster found in the assets folder '{item_dir}'")
else:
logger.warning(f"Asset Warning: No poster '{name}' found in the assets folders")
@ -185,7 +186,7 @@ class Overlays:
def get_text(text):
text = text[5:-1]
if text in util.special_text_overlays:
if f"text({text})" in util.special_text_overlays:
per = text.endswith("%")
flat = text.endswith("#")
text_rating_type = text[:-1] if per or flat else text
@ -203,11 +204,11 @@ class Overlays:
for over_name in applied_names:
overlay = properties[over_name]
if over_name.startswith("text"):
if over_name[5:-1] in util.special_text_overlays:
if overlay.name.startswith("text"):
if overlay.name in util.special_text_overlays:
image_box = overlay.image.size if overlay.image else None
try:
overlay_image, addon_box = overlay.get_backdrop((canvas_width, canvas_height), box=image_box, text=get_text(over_name))
overlay_image, addon_box = overlay.get_backdrop((canvas_width, canvas_height), box=image_box, text=get_text(overlay.name))
except Failed as e:
logger.warning(e)
continue
@ -239,10 +240,10 @@ class Overlays:
break
over_name = sorted_weights[o][1]
overlay = properties[over_name]
if over_name.startswith("text"):
if overlay.name.startswith("text"):
image_box = overlay.image.size if overlay.image else None
try:
overlay_image, addon_box = overlay.get_backdrop((canvas_width, canvas_height), box=image_box, text=get_text(over_name), new_cords=cord)
overlay_image, addon_box = overlay.get_backdrop((canvas_width, canvas_height), box=image_box, text=get_text(overlay.name), new_cords=cord)
except Failed as e:
logger.warning(e)
continue
@ -302,8 +303,9 @@ class Overlays:
logger.separator(f"Gathering Items for {k} Overlay", space=False, border=False)
if builder.overlay.name not in properties:
properties[builder.overlay.name] = builder.overlay
if builder.overlay.mapping_name in properties:
raise Failed(f"Overlay Error: Overlay {builder.overlay.mapping_name} already exists ")
properties[builder.overlay.mapping_name] = builder.overlay
for method, value in builder.builders:
logger.debug("")
@ -323,11 +325,11 @@ class Overlays:
for item in builder.added_items:
key_to_item[item.ratingKey] = item
added_titles.append(item)
if item.ratingKey not in properties[builder.overlay.name].keys:
properties[builder.overlay.name].keys.append(item.ratingKey)
if item.ratingKey not in properties[builder.overlay.mapping_name].keys:
properties[builder.overlay.mapping_name].keys.append(item.ratingKey)
if added_titles:
logger.debug(f"{len(added_titles)} Titles Found: {[self.library.get_item_sort_title(a, atr='title') for a in added_titles]}")
logger.info(f"{len(added_titles) if added_titles else 'No'} Items found for {builder.overlay.name}")
logger.info(f"{len(added_titles) if added_titles else 'No'} Items found for {builder.overlay.mapping_name}")
except NotScheduled as e:
logger.info(e)
except Failed as e:

View file

@ -93,7 +93,7 @@ parental_labels = [f"{t.capitalize()}:{v}" for t in parental_types for v in pare
github_base = "https://raw.githubusercontent.com/meisnate12/Plex-Meta-Manager-Configs/master/"
previous_time = None
start_time = None
special_text_overlays = [f"{a}{s}" for a in ["audience_rating", "critic_rating", "user_rating"] for s in ["", "%", "#"]]
special_text_overlays = [f"text({a}{s})" for a in ["audience_rating", "critic_rating", "user_rating"] for s in ["", "%", "#"]]
def make_ordinal(n):
return f"{n}{'th' if 11 <= (n % 100) <= 13 else ['th', 'st', 'nd', 'rd', 'th'][min(n % 10, 4)]}"
@ -902,9 +902,10 @@ def parse_cords(data, parent, required=False):
class Overlay:
def __init__(self, config, library, overlay_data, suppress):
def __init__(self, config, library, mapping_name, overlay_data, suppress):
self.config = config
self.library = library
self.mapping_name = mapping_name
self.data = overlay_data
self.suppress = suppress
self.keys = []
@ -924,16 +925,14 @@ class Overlay:
self.font_color = None
self.addon_offset = None
self.addon_align = None
logger.debug("")
logger.debug("Validating Method: overlay")
logger.debug(f"Value: {self.data}")
if not isinstance(self.data, dict):
self.data = {"name": str(self.data)}
logger.warning(f"Overlay Warning: No overlay attribute using mapping name {self.data} as the overlay name")
if "name" not in self.data or not self.data["name"]:
raise Failed(f"Overlay Error: overlay must have the name attribute")
self.name = str(self.data["name"])
self.name = str(self.data["name"]) if "name" in self.data and self.data["name"] else self.mapping_name
if "group" in self.data and self.data["group"]:
self.group = str(self.data["group"])
@ -1024,13 +1023,13 @@ class Overlay:
self.addon_align = parse("Overlay", "addon_align", self.data["addon_align"], parent="overlay", options=["left", "right", "top", "bottom"]) if "addon_align" in self.data else "left"
image_compare = None
if self.config.Cache:
_, image_compare, _ = self.config.Cache.query_image_map(self.name, f"{self.library.image_table_name}_overlays")
_, image_compare, _ = self.config.Cache.query_image_map(self.mapping_name, f"{self.library.image_table_name}_overlays")
overlay_size = os.stat(self.path).st_size
self.updated = not image_compare or str(overlay_size) != str(image_compare)
try:
self.image = Image.open(self.path).convert("RGBA")
if self.config.Cache:
self.config.Cache.update_image_map(self.name, f"{self.library.image_table_name}_overlays", self.name, overlay_size)
self.config.Cache.update_image_map(self.mapping_name, f"{self.library.image_table_name}_overlays", self.name, overlay_size)
except OSError:
raise Failed(f"Overlay Error: overlay image {self.path} failed to load")
match = re.search("\\(([^)]+)\\)", self.name)
@ -1063,11 +1062,10 @@ class Overlay:
self.font_color = ImageColor.getcolor(self.data["font_color"], "RGBA")
except ValueError:
raise Failed(f"Overlay Error: overlay font_color: {self.data['font_color']} invalid")
text = self.name[5:-1]
if text not in special_text_overlays:
if self.name not in special_text_overlays:
box = self.image.size if self.image else None
self.portrait, self.portrait_box = self.get_backdrop(portrait_dim, box=box, text=text)
self.landscape, self.landscape_box = self.get_backdrop(landscape_dim, box=box, text=text)
self.portrait, self.portrait_box = self.get_backdrop(portrait_dim, box=box, text=self.name[5:-1])
self.landscape, self.landscape_box = self.get_backdrop(landscape_dim, box=box, text=self.name[5:-1])
else:
if not self.path:
clean_name, _ = validate_filename(self.name)
@ -1076,7 +1074,7 @@ class Overlay:
raise Failed(f"Overlay Error: Overlay Image not found at: {self.path}")
image_compare = None
if self.config.Cache:
_, image_compare, _ = self.config.Cache.query_image_map(self.name, f"{self.library.image_table_name}_overlays")
_, image_compare, _ = self.config.Cache.query_image_map(self.mapping_name, f"{self.library.image_table_name}_overlays")
overlay_size = os.stat(self.path).st_size
self.updated = not image_compare or str(overlay_size) != str(image_compare)
try:
@ -1085,7 +1083,7 @@ class Overlay:
self.portrait, self.portrait_box = self.get_backdrop(portrait_dim, box=self.image.size)
self.landscape, self.landscape_box = self.get_backdrop(landscape_dim, box=self.image.size)
if self.config.Cache:
self.config.Cache.update_image_map(self.name, f"{self.library.image_table_name}_overlays", self.name, overlay_size)
self.config.Cache.update_image_map(self.mapping_name, f"{self.library.image_table_name}_overlays", self.mapping_name, overlay_size)
except OSError:
raise Failed(f"Overlay Error: overlay image {self.path} failed to load")
@ -1162,7 +1160,7 @@ class Overlay:
return overlay_image, (x_cord, y_cord)
def get_overlay_compare(self):
output = self.name
output = f"{self.mapping_name}|{self.name}"
if self.group:
output += f"{self.group}{self.weight}"
if self.has_coordinates():
@ -1171,7 +1169,7 @@ class Overlay:
output += f"{self.font_name}{self.font_size}"
if self.back_box:
output += f"{self.back_box[0]}{self.back_box[1]}"
for value in [self.font_color, self.back_color, self.back_radius, self.back_padding, self.back_line_color, self.back_line_width]:
for value in [self.addon_align, self.addon_offset, self.font_color, self.back_color, self.back_radius, self.back_padding, self.back_line_color, self.back_line_width]:
if value is not None:
output += f"{value}"
return output