[50] fix overlapping overlays

pull/935/head
meisnate12 3 years ago
parent ee49b42b15
commit b6c7677025

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

@ -260,7 +260,7 @@ class CollectionBuilder:
suppress = util.get_list(data[methods["suppress_overlays"]]) suppress = util.get_list(data[methods["suppress_overlays"]])
else: else:
logger.error(f"Overlay Error: suppress_overlays attribute is blank") 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.sync_to_users = None
self.valid_users = [] self.valid_users = []
@ -1775,7 +1775,7 @@ class CollectionBuilder:
error = f"{self.Type} Error: {final_attr} {method} attribute does not work for music libraries" 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: 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" 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" error = f"{self.Type} Error: {final_attr} {method} attribute is blank"
else: else:
if final_attr.startswith(("any", "all")): if final_attr.startswith(("any", "all")):

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

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

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

@ -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/" github_base = "https://raw.githubusercontent.com/meisnate12/Plex-Meta-Manager-Configs/master/"
previous_time = None previous_time = None
start_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): def make_ordinal(n):
return f"{n}{'th' if 11 <= (n % 100) <= 13 else ['th', 'st', 'nd', 'rd', 'th'][min(n % 10, 4)]}" 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: class Overlay:
def __init__(self, config, library, overlay_data, suppress): def __init__(self, config, library, mapping_name, overlay_data, suppress):
self.config = config self.config = config
self.library = library self.library = library
self.mapping_name = mapping_name
self.data = overlay_data self.data = overlay_data
self.suppress = suppress self.suppress = suppress
self.keys = [] self.keys = []
@ -924,16 +925,14 @@ class Overlay:
self.font_color = None self.font_color = None
self.addon_offset = None self.addon_offset = None
self.addon_align = None self.addon_align = None
logger.debug("") logger.debug("")
logger.debug("Validating Method: overlay") logger.debug("Validating Method: overlay")
logger.debug(f"Value: {self.data}") logger.debug(f"Value: {self.data}")
if not isinstance(self.data, dict): if not isinstance(self.data, dict):
self.data = {"name": str(self.data)} self.data = {"name": str(self.data)}
logger.warning(f"Overlay Warning: No overlay attribute using mapping name {self.data} as the overlay name") logger.warning(f"Overlay Warning: No overlay attribute using mapping name {self.data} as the overlay name")
self.name = str(self.data["name"]) if "name" in self.data and self.data["name"] else self.mapping_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"])
if "group" in self.data and self.data["group"]: if "group" in self.data and self.data["group"]:
self.group = str(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" 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 image_compare = None
if self.config.Cache: 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 overlay_size = os.stat(self.path).st_size
self.updated = not image_compare or str(overlay_size) != str(image_compare) self.updated = not image_compare or str(overlay_size) != str(image_compare)
try: try:
self.image = Image.open(self.path).convert("RGBA") self.image = Image.open(self.path).convert("RGBA")
if self.config.Cache: 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: except OSError:
raise Failed(f"Overlay Error: overlay image {self.path} failed to load") raise Failed(f"Overlay Error: overlay image {self.path} failed to load")
match = re.search("\\(([^)]+)\\)", self.name) match = re.search("\\(([^)]+)\\)", self.name)
@ -1063,11 +1062,10 @@ class Overlay:
self.font_color = ImageColor.getcolor(self.data["font_color"], "RGBA") self.font_color = ImageColor.getcolor(self.data["font_color"], "RGBA")
except ValueError: except ValueError:
raise Failed(f"Overlay Error: overlay font_color: {self.data['font_color']} invalid") raise Failed(f"Overlay Error: overlay font_color: {self.data['font_color']} invalid")
text = self.name[5:-1] if self.name not in special_text_overlays:
if text not in special_text_overlays:
box = self.image.size if self.image else None box = self.image.size if self.image else None
self.portrait, self.portrait_box = self.get_backdrop(portrait_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=text) self.landscape, self.landscape_box = self.get_backdrop(landscape_dim, box=box, text=self.name[5:-1])
else: else:
if not self.path: if not self.path:
clean_name, _ = validate_filename(self.name) clean_name, _ = validate_filename(self.name)
@ -1076,7 +1074,7 @@ class Overlay:
raise Failed(f"Overlay Error: Overlay Image not found at: {self.path}") raise Failed(f"Overlay Error: Overlay Image not found at: {self.path}")
image_compare = None image_compare = None
if self.config.Cache: 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 overlay_size = os.stat(self.path).st_size
self.updated = not image_compare or str(overlay_size) != str(image_compare) self.updated = not image_compare or str(overlay_size) != str(image_compare)
try: try:
@ -1085,7 +1083,7 @@ class Overlay:
self.portrait, self.portrait_box = self.get_backdrop(portrait_dim, box=self.image.size) 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) self.landscape, self.landscape_box = self.get_backdrop(landscape_dim, box=self.image.size)
if self.config.Cache: 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: except OSError:
raise Failed(f"Overlay Error: overlay image {self.path} failed to load") 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) return overlay_image, (x_cord, y_cord)
def get_overlay_compare(self): def get_overlay_compare(self):
output = self.name output = f"{self.mapping_name}|{self.name}"
if self.group: if self.group:
output += f"{self.group}{self.weight}" output += f"{self.group}{self.weight}"
if self.has_coordinates(): if self.has_coordinates():
@ -1171,7 +1169,7 @@ class Overlay:
output += f"{self.font_name}{self.font_size}" output += f"{self.font_name}{self.font_size}"
if self.back_box: if self.back_box:
output += f"{self.back_box[0]}{self.back_box[1]}" 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: if value is not None:
output += f"{value}" output += f"{value}"
return output return output

Loading…
Cancel
Save