From 57de771ca28f68ee25855f8854ee4b56e6ce36c7 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Tue, 6 Jul 2021 09:55:52 -0400 Subject: [PATCH 1/7] fixed overlay --- modules/plex.py | 4 +++- modules/radarr.py | 2 +- modules/sonarr.py | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/plex.py b/modules/plex.py index 2d5975ab..0ad4747e 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -814,7 +814,9 @@ class Plex: if len(matches) > 0: episode_poster = ImageData("asset_directory", os.path.abspath(matches[0]), prefix=f"{item.title} {episode.seasonEpisode.upper()}'s ", is_url=False) self.upload_images(episode, poster=episode_poster) - if not found_one: + if not found_one and overlay: + self.upload_images(item, overlay=overlay) + elif not found_one: logger.error(f"Asset Warning: No asset folder found called '{name}'") def find_collection_assets(self, item, name=None): diff --git a/modules/radarr.py b/modules/radarr.py index 3dd50dfc..86ab67de 100644 --- a/modules/radarr.py +++ b/modules/radarr.py @@ -71,7 +71,7 @@ class Radarr: logger.info("") logger.info(f"{apply_tags_translation[apply_tags].capitalize()} Radarr Tags: {tags}") - edited, not_exists = self.api.edit_multiple_movies(tmdb_ids, tags=tags, apply_tags=apply_tags) + edited, not_exists = self.api.edit_multiple_movies(tmdb_ids, tags=tags, apply_tags=apply_tags_translation[apply_tags]) if len(edited) > 0: logger.info("") diff --git a/modules/sonarr.py b/modules/sonarr.py index 80bbb65e..150e32dd 100644 --- a/modules/sonarr.py +++ b/modules/sonarr.py @@ -84,12 +84,12 @@ class Sonarr: logger.info("") logger.info(f"{apply_tags_translation[apply_tags].capitalize()} Sonarr Tags: {tags}") - edited, not_exists = self.api.edit_multiple_series(tvdb_ids, tags=tags, apply_tags=apply_tags) + edited, not_exists = self.api.edit_multiple_series(tvdb_ids, tags=tags, apply_tags=apply_tags_translation[apply_tags]) if len(edited) > 0: logger.info("") for series in edited: - logger.info(f"Radarr Tags | {series.title:<25} | {series.tags}") + logger.info(f"Sonarr Tags | {series.title:<25} | {series.tags}") logger.info(f"{len(edited)} Series edited in Sonarr") if len(not_exists) > 0: From 470b1baf0f4e5eece0ebfd9ccb3f579bf07d7f41 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Tue, 6 Jul 2021 11:46:29 -0400 Subject: [PATCH 2/7] overlay wait --- modules/plex.py | 4 +++- modules/util.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/modules/plex.py b/modules/plex.py index 0ad4747e..f39b2845 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -1,4 +1,4 @@ -import glob, logging, os, plexapi, requests, shutil +import glob, logging, os, plexapi, requests, shutil, time from modules import builder, util from modules.meta import Metadata from modules.util import Failed, ImageData @@ -463,6 +463,8 @@ class Plex: with open(temp_image, "wb") as handler: handler.write(og_image) shutil.copyfile(temp_image, os.path.join(overlay_folder, f"{item.ratingKey}.png")) + while util.is_locked(temp_image): + time.sleep(1) new_poster = Image.open(temp_image) new_poster = new_poster.resize(overlay_image.size, Image.ANTIALIAS) new_poster.paste(overlay_image, (0, 0), overlay_image) diff --git a/modules/util.py b/modules/util.py index f4c9ce59..cc058f18 100644 --- a/modules/util.py +++ b/modules/util.py @@ -420,3 +420,18 @@ def validate_filename(filename): else: mapping_name = sanitize_filename(filename) return mapping_name, f"Log Folder Name: {filename} is invalid using {mapping_name}" + +def is_locked(filepath): + locked = None + file_object = None + if os.path.exists(filepath): + try: + file_object = open(filepath, 'a', 8) + if file_object: + locked = False + except IOError as message: + locked = True + finally: + if file_object: + file_object.close() + return locked From ab2c2d497307fefb89d511160a8979972efa1ec1 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Tue, 6 Jul 2021 14:54:53 -0400 Subject: [PATCH 3/7] catch overlay error --- modules/builder.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/builder.py b/modules/builder.py index 840b432e..1ee78a48 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -2,7 +2,7 @@ import logging, os, re from datetime import datetime, timedelta from modules import anidb, anilist, icheckmovies, imdb, letterboxd, mal, plex, radarr, sonarr, tautulli, tmdb, trakttv, tvdb, util from modules.util import Failed, ImageData -from PIL import Image +from PIL import Image, UnidentifiedImageError from plexapi.exceptions import BadRequest, NotFound from plexapi.video import Movie, Show from urllib.parse import quote @@ -1707,7 +1707,11 @@ class CollectionBuilder: if int(item.ratingKey) in rating_keys: rating_keys.remove(int(item.ratingKey)) if self.details["item_assets"] or overlay is not None: - self.library.update_item_from_assets(item, overlay=overlay) + try: + self.library.update_item_from_assets(item, overlay=overlay) + except UnidentifiedImageError: + util.print_stacktrace() + logger.error(f"Overlay Error: Overlay Failed for {item.title}") self.library.edit_tags("label", item, add_tags=add_tags, remove_tags=remove_tags, sync_tags=sync_tags) if "item_radarr_tag" in self.item_details and item.ratingKey in self.library.movie_rating_key_map: tmdb_ids.append(self.library.movie_rating_key_map[item.ratingKey]) From b5dafed1d83c547b37ba962070ee15d15b352308 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Tue, 6 Jul 2021 15:17:06 -0400 Subject: [PATCH 4/7] fixed 500 Error --- modules/builder.py | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/builder.py b/modules/builder.py index 1ee78a48..736e4fc7 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -1664,6 +1664,7 @@ class CollectionBuilder: logger.info("") util.separator(f"Removed from {self.name} Collection", space=False, border=False) logger.info("") + self.library.reload(item) logger.info(f"{self.name} Collection | - | {item.title}") if self.smart_label_collection: self.library.query_data(item.removeLabel, self.name) From 0129210d76add06768475b721fd8425cd61ba1f7 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Tue, 6 Jul 2021 15:59:55 -0400 Subject: [PATCH 5/7] check status code --- modules/builder.py | 5 ++--- modules/plex.py | 5 ++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/builder.py b/modules/builder.py index 736e4fc7..7e4defe0 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -1710,9 +1710,8 @@ class CollectionBuilder: if self.details["item_assets"] or overlay is not None: try: self.library.update_item_from_assets(item, overlay=overlay) - except UnidentifiedImageError: - util.print_stacktrace() - logger.error(f"Overlay Error: Overlay Failed for {item.title}") + except Failed as e: + logger.error(e) self.library.edit_tags("label", item, add_tags=add_tags, remove_tags=remove_tags, sync_tags=sync_tags) if "item_radarr_tag" in self.item_details and item.ratingKey in self.library.movie_rating_key_map: tmdb_ids.append(self.library.movie_rating_key_map[item.ratingKey]) diff --git a/modules/plex.py b/modules/plex.py index f39b2845..f6045fef 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -459,7 +459,10 @@ class Plex: if self.config.Cache: image, _, image_overlay = self.config.Cache.query_image_map(item.ratingKey, self.original_mapping_name, "poster") if poster_uploaded or not image_overlay or image_overlay != overlay_name: - og_image = requests.get(item.posterUrl).content + response = requests.get(item.posterUrl) + if response.status_code >= 400: + raise Failed(f"Overlay Error: Overlay Failed for {item.title}") + og_image = response.content with open(temp_image, "wb") as handler: handler.write(og_image) shutil.copyfile(temp_image, os.path.join(overlay_folder, f"{item.ratingKey}.png")) From db71b30da3c07e25072dd5ba6625a0ca8d3732fa Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Tue, 6 Jul 2021 16:49:04 -0400 Subject: [PATCH 6/7] fixed resolution for tv shows --- modules/plex.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/plex.py b/modules/plex.py index f6045fef..d9f55fa9 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -503,6 +503,8 @@ class Plex: @retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_failed) def get_search_choices(self, search_name, title=True): final_search = search_translation[search_name] if search_name in search_translation else search_name + if final_search == "resolution" and self.is_show: + final_search = "episode.resolution" try: choices = {} for choice in self.Plex.listFilterChoices(final_search): From 4ca862a5fd049471efdf6bd035d279c52a37e2c3 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Tue, 6 Jul 2021 16:57:00 -0400 Subject: [PATCH 7/7] update pull request template --- .github/ISSUE_TEMPLATE/feature_request.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 8263b029..86f37cee 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -7,6 +7,10 @@ assignees: 'meisnate12' --- + + **Is your feature request related to a problem? Please describe.** A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]