From f053b7d3266a6902668ae5f19f76712b2e47fd38 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Tue, 26 Apr 2022 11:28:04 -0400 Subject: [PATCH] [40] fix overlay caching --- VERSION | 2 +- docs/config/paths.md | 2 +- docs/metadata/details/schedule.md | 8 +++-- modules/library.py | 4 +-- modules/meta.py | 2 +- modules/overlays.py | 58 +++++++++++++++++-------------- 6 files changed, 41 insertions(+), 35 deletions(-) diff --git a/VERSION b/VERSION index 87631de9..128ef6f1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.16.5-develop39 +1.16.5-develop40 diff --git a/docs/config/paths.md b/docs/config/paths.md index aa2a3eab..ca0d8264 100644 --- a/docs/config/paths.md +++ b/docs/config/paths.md @@ -110,7 +110,7 @@ In this example, multiple overlay file path types are defined for the `"TV Shows ```yaml libraries: TV Shows: - overlay_apth: + overlay_path: - file: config/overlays.yml - folder: config/overlay configs/ - git: PMM/overlays/imdb diff --git a/docs/metadata/details/schedule.md b/docs/metadata/details/schedule.md index 5c0d789e..d307210f 100644 --- a/docs/metadata/details/schedule.md +++ b/docs/metadata/details/schedule.md @@ -23,14 +23,18 @@ libraries: Movies: metadata_path: - file: config/Movies.yml - schedule: weekly(friday) + schedule: weekly(monday) - git: meisnate12/MovieCharts + schedule: weekly(tuesday) - git: meisnate12/Studios + schedule: weekly(wednesday) - git: meisnate12/IMDBGenres + schedule: weekly(thursday) - git: meisnate12/People + schedule: weekly(friday) overlay_path: - git: PMM/overlays/imdb - schedule: weekly(saturday) + schedule: weekly(saturday) operations: mass_critic_rating_update: tmdb playlist_files: diff --git a/modules/library.py b/modules/library.py index dcfb9ce3..1a8b3d29 100644 --- a/modules/library.py +++ b/modules/library.py @@ -1,11 +1,9 @@ -import os, shutil, time +import os from abc import ABC, abstractmethod from modules import util from modules.meta import MetadataFile, OverlayFile from modules.operations import Operations from modules.util import Failed, ImageData -from PIL import Image -from plexapi.exceptions import BadRequest from ruamel import yaml logger = util.logger diff --git a/modules/meta.py b/modules/meta.py index 80aa53ff..73e528ec 100644 --- a/modules/meta.py +++ b/modules/meta.py @@ -241,7 +241,7 @@ class DataFile: return new_attributes def external_templates(self, data): - if "external_templates" in data and data["external_templates"]: + if data and "external_templates" in data and data["external_templates"]: files = util.load_files(data["external_templates"], "external_templates") if not files: logger.error("Config Error: No Paths Found for external_templates") diff --git a/modules/overlays.py b/modules/overlays.py index 538d82ef..84215f24 100644 --- a/modules/overlays.py +++ b/modules/overlays.py @@ -33,8 +33,9 @@ class Overlays: logger.separator(f"Removing {old_overlay.title}") logger.info("") for i, item in enumerate(label_items, 1): - logger.ghost(f"Restoring {old_overlay.title}: {i}/{len(label_items)} {item.title}") - self.remove_overlay(item, old_overlay.title, [ + item_title = self.get_item_sort_title(item, atr="title") + logger.ghost(f"Restoring {old_overlay.title}: {i}/{len(label_items)} {item_title}") + self.remove_overlay(item, item_title, old_overlay.title, [ os.path.join(self.library.overlay_folder, old_overlay.title[:-8], f"{item.ratingKey}.png") ]) @@ -50,8 +51,9 @@ class Overlays: if remove_overlays: logger.separator(f"Removing Overlays for the {self.library.name} Library") for i, item in enumerate(remove_overlays, 1): - logger.ghost(f"Restoring: {i}/{len(remove_overlays)} {item.title}") - self.remove_overlay(item, "Overlay", [ + item_title = self.get_item_sort_title(item, atr="title") + logger.ghost(f"Restoring: {i}/{len(remove_overlays)} {item_title}") + self.remove_overlay(item, item_title, "Overlay", [ os.path.join(self.library.overlay_backup, f"{item.ratingKey}.png"), os.path.join(self.library.overlay_backup, f"{item.ratingKey}.jpg") ]) @@ -64,18 +66,10 @@ class Overlays: logger.info("") logger.separator(f"Applying Overlays for the {self.library.name} Library") logger.info("") - def get_item_sort_title(item_to_sort): - if isinstance(item_to_sort, Album): - return f"{item_to_sort.titleSort} Album {item_to_sort.title}" - elif isinstance(item_to_sort, Season): - return f"{item_to_sort.titleSort} Season {item_to_sort.seasonNumber}" - elif isinstance(item_to_sort, Episode): - return f"{item_to_sort.titleSort} {item_to_sort.seasonEpisode.upper()}" - else: - return item_to_sort.titleSort - for i, (over_key, (item, over_names)) in enumerate(sorted(key_to_overlays.items(), key=lambda io: get_item_sort_title(io[1][0])), 1): + for i, (over_key, (item, over_names)) in enumerate(sorted(key_to_overlays.items(), key=lambda io: self.get_item_sort_title(io[1][0])), 1): try: - logger.ghost(f"Overlaying: {i}/{len(key_to_overlays)} {item.title}") + item_title = self.get_item_sort_title(item, atr="title") + logger.ghost(f"Overlaying: {i}/{len(key_to_overlays)} {item_title}") image_compare = None overlay_compare = None poster = None @@ -123,7 +117,7 @@ class Overlays: changed_image = True image_response = self.config.get(new_backup) if image_response.status_code >= 400: - raise Failed(f"Overlay Error: Poster Download Failed for {item.title}") + raise Failed(f"{item_title[:60]:<60} | Overlay Error: Poster Download Failed") i_ext = "jpg" if image_response.headers["Content-Type"] == "image/jpeg" else "png" backup_image_path = os.path.join(self.library.overlay_backup, f"{item.ratingKey}.{i_ext}") with open(backup_image_path, "wb") as handler: @@ -134,7 +128,7 @@ class Overlays: poster_compare = None if poster is None and has_original is None: - logger.error(f"Overlay Error: No poster found for {item.title}") + logger.error(f"{item_title[:60]:<60} | Overlay Error: No poster found") elif changed_image or overlay_change: try: new_poster = Image.open(poster.location if poster else has_original).convert("RGBA") @@ -156,20 +150,30 @@ class Overlays: self.library.edit_tags("label", item, add_tags=["Overlay"], do_print=False) self.library.reload(item, force=True) poster_compare = poster.compare if poster else item.thumb - logger.info(f"Detail: Overlays: {', '.join(over_names)} applied to {item.title}") + logger.info(f"{item_title[:60]:<60} | Overlays Applied: {', '.join(over_names)}") except (OSError, BadRequest) as e: logger.stacktrace() - raise Failed(f"Overlay Error: {e}") - else: - logger.error(f"Overlay Update Not Needed for {item.title}") + raise Failed(f"{item_title[:60]:<60} | Overlay Error: {e}") + elif self.library.show_asset_not_needed: + logger.error(f"{item_title[:60]:<60} | Overlay Update Not Needed") if self.config.Cache and poster_compare: - self.config.Cache.update_image_map(item.ratingKey, self.library.image_table_name, item.thumb, - poster_compare, overlay=','.join(over_names)) + self.config.Cache.update_image_map(item.ratingKey, f"{self.library.image_table_name}_overlays", + item.thumb, poster_compare, overlay=','.join(over_names)) except Failed as e: logger.error(e) logger.exorcise() + def get_item_sort_title(self, item_to_sort, atr="titleSort"): + if isinstance(item_to_sort, Album): + return f"{getattr(item_to_sort.artist(), atr)} Album {getattr(item_to_sort, atr)}" + elif isinstance(item_to_sort, Season): + return f"{getattr(item_to_sort.show(), atr)} Season {item_to_sort.seasonNumber}" + elif isinstance(item_to_sort, Episode): + return f"{getattr(item_to_sort.show(), atr)} {item_to_sort.seasonEpisode.upper()}" + else: + return getattr(item_to_sort, atr) + def compile_overlays(self): key_to_item = {} properties = {} @@ -208,11 +212,11 @@ class Overlays: if builder.added_items: for item in builder.added_items: key_to_item[item.ratingKey] = item - added_titles.append(item.title) + added_titles.append(item) if item.ratingKey not in properties[builder.overlay]["keys"]: properties[builder.overlay]["keys"].append(item.ratingKey) if added_titles: - logger.debug(f"{len(added_titles)} Titles Found: {added_titles}") + logger.debug(f"{len(added_titles)} Titles Found: {[self.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}") except Failed as e: logger.error(e) @@ -286,7 +290,7 @@ class Overlays: items = self.library.search(label=label, libtype=libtype) return items if not ignore else [o for o in items if o.ratingKey not in ignore] - def remove_overlay(self, item, label, locations): + def remove_overlay(self, item, item_title, label, locations): try: poster, _, _, _ = self.library.find_item_assets(item) except Failed: @@ -307,4 +311,4 @@ class Overlays: if original: os.remove(original) else: - logger.error(f"No Poster found to restore for {item.title}") \ No newline at end of file + logger.error(f"No Poster found to restore for {item_title}") \ No newline at end of file