From ce0ae7e82f58286a2564a6f0ae6776a7cc7b1465 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Wed, 19 Oct 2022 16:13:38 -0400 Subject: [PATCH] [137] fix album overlays --- VERSION | 2 +- modules/overlay.py | 25 ++++++++++++++++++++++++- modules/overlays.py | 11 ++++------- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/VERSION b/VERSION index 776b5d49..1b8c48d6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.17.3-develop136 +1.17.3-develop137 diff --git a/modules/overlay.py b/modules/overlay.py index f60d8b72..b5f67fbe 100644 --- a/modules/overlay.py +++ b/modules/overlay.py @@ -1,13 +1,16 @@ import os, re, time from datetime import datetime -from PIL import Image, ImageColor, ImageDraw, ImageFont from modules import util from modules.util import Failed +from PIL import Image, ImageColor, ImageDraw, ImageFont +from plexapi.audio import Album +from plexapi.video import Episode logger = util.logger portrait_dim = (1000, 1500) landscape_dim = (1920, 1080) +square_dim = (1000, 1000) old_special_text = [f"{a}{s}" for a in ["audience_rating", "critic_rating", "user_rating"] for s in ["", "0", "%", "#"]] float_vars = ["audience_rating", "critic_rating", "user_rating"] int_vars = ["runtime", "season_number", "episode_number", "episode_count", "versions"] @@ -106,6 +109,13 @@ def parse_cords(data, parent, required=False): return horizontal_align, horizontal_offset, vertical_align, vertical_offset +def get_canvas_size(item): + if isinstance(item, Episode): + return landscape_dim + elif isinstance(item, Album): + return square_dim + else: + return portrait_dim class Overlay: def __init__(self, config, library, original_mapping_name, overlay_data, suppress, level): @@ -122,6 +132,8 @@ class Overlay: self.landscape_box = None self.portrait = None self.portrait_box = None + self.square = None + self.square_box = None self.group = None self.queue = None self.weight = None @@ -326,9 +338,11 @@ class Overlay: box = self.image.size if self.image else None 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]) + self.square, self.square_box = self.get_backdrop(square_dim, box=box, text=self.name[5:-1]) elif self.name.startswith("backdrop"): self.portrait, self.portrait_box = self.get_backdrop(portrait_dim, box=self.back_box) self.landscape, self.landscape_box = self.get_backdrop(landscape_dim, box=self.back_box) + self.square, self.square_box = self.get_backdrop(square_dim, box=self.back_box) else: if not self.path: clean_name, _ = util.validate_filename(self.name) @@ -345,6 +359,7 @@ class Overlay: if self.has_coordinates(): 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.square, self.square_box = self.get_backdrop(square_dim, box=self.image.size) if self.config.Cache: self.config.Cache.update_image_map(self.mapping_name, f"{self.library.image_table_name}_overlays", self.mapping_name, overlay_size) except OSError: @@ -500,3 +515,11 @@ class Overlay: else: ha, ho, va, vo = new_cords return get_cord(ho, canvas_box[0], box[0], ha), get_cord(vo, canvas_box[1], box[1], va) + + def get_canvas(self, item): + if isinstance(item, Episode): + return self.landscape, self.landscape_box + elif isinstance(item, Album): + return self.square, self.square_box + else: + return self.portrait, self.portrait_box diff --git a/modules/overlays.py b/modules/overlays.py index b124ef29..ccdb987f 100644 --- a/modules/overlays.py +++ b/modules/overlays.py @@ -193,8 +193,7 @@ class Overlays: logger.error(f"{item_title[:60]:<60} | Overlay Error: No poster found") elif self.library.reapply_overlays or changed_image or overlay_change: try: - canvas_width = 1920 if isinstance(item, Episode) else 1000 - canvas_height = 1080 if isinstance(item, Episode) else 1500 + canvas_width, canvas_height = overlay.get_canvas_size(item) new_poster = Image.open(poster.location if poster else has_original) \ .convert("RGB").resize((canvas_width, canvas_height), Image.ANTIALIAS) @@ -296,20 +295,18 @@ class Overlays: continue new_poster.paste(overlay_image, (0, 0), overlay_image) else: - overlay_image = current_overlay.landscape if isinstance(item, Episode) else current_overlay.portrait - addon_box = current_overlay.landscape_box if isinstance(item, Episode) else current_overlay.portrait_box + overlay_image, addon_box = current_overlay.get_canvas(item) new_poster.paste(overlay_image, (0, 0), overlay_image) if current_overlay.image: new_poster.paste(current_overlay.image, addon_box, current_overlay.image) elif current_overlay.name == "backdrop": - overlay_image = current_overlay.landscape if isinstance(item, Episode) else current_overlay.portrait + overlay_image, _ = current_overlay.get_canvas(item) new_poster.paste(overlay_image, (0, 0), overlay_image) else: if current_overlay.has_coordinates(): + overlay_image, overlay_box = current_overlay.get_canvas(item) if current_overlay.portrait is not None: - overlay_image = current_overlay.landscape if isinstance(item, Episode) else current_overlay.portrait new_poster.paste(overlay_image, (0, 0), overlay_image) - overlay_box = current_overlay.landscape_box if isinstance(item, Episode) else current_overlay.portrait_box new_poster.paste(current_overlay.image, overlay_box, current_overlay.image) else: new_poster = new_poster.resize(current_overlay.image.size, Image.ANTIALIAS)