[137] fix album overlays

pull/1124/head
meisnate12 2 years ago
parent df85da05e7
commit ce0ae7e82f

@ -1 +1 @@
1.17.3-develop136
1.17.3-develop137

@ -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

@ -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)

Loading…
Cancel
Save