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