From 8784f4ab9ad8b9c75cb6dbf564403c131a7115d7 Mon Sep 17 00:00:00 2001 From: Nils Simons Date: Fri, 11 Oct 2024 01:39:23 +0200 Subject: [PATCH] Bug fixes Fixed "PermissionError #14: Resolved an unhandled exception in script #14" by moving the rename operation to after the image is saved. Fixed "Failed to execute script 'window' due to unhandled exception: 'title' #9" by skipping images when the name is not found. Fixed missing Timestamp error: Corrected an issue where a missing Timestamp in the metadata caused errors. --- files/main.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/files/main.py b/files/main.py index 6edc022..053993a 100644 --- a/files/main.py +++ b/files/main.py @@ -33,8 +33,11 @@ def mainProcess(browserPath, window, editedW): window['-PROGRESS_BAR-'].update(progress, visible=True) #SEARCH MEDIA ASSOCIATED TO JSON - - titleOriginal = data['title'] # Store metadata into vars + try: + titleOriginal = data['title'] # Store metadata into vars + except KeyError as error: + print('Title not found in metadata') + errorCounter += 1 try: title = searchMedia(path, titleOriginal, mediaMoved, nonEditedMediaPath, editedWord) @@ -46,21 +49,29 @@ def mainProcess(browserPath, window, editedW): filepath = path + "\\" + title if title == "None": - print(titleOriginal + " not found") + try: + print(titleOriginal + " not found") + except Exception as e: + print('Unknow Title not found') errorCounter += 1 continue # METADATA EDITION - timeStamp = int(data['photoTakenTime']['timestamp']) # Get creation time + try: + timeStamp = int(data['photoTakenTime']['timestamp']) # Get creation time + except KeyError: + timeStamp = 946681200 # 1 Jan 2000 0H00 + print("No photoTaken time found in metadata") + errorCounter += 1 + print(filepath) if title.rsplit('.', 1)[1].casefold() in piexifCodecs: # If EXIF is supported try: - im = Image.open(filepath) - rgb_im = im.convert('RGB') - os.replace(filepath, filepath.rsplit('.', 1)[0] + ".jpg") - filepath = filepath.rsplit('.', 1)[0] + ".jpg" - rgb_im.save(filepath) + with Image.open(filepath) as im: + rgb_im = im.convert('RGB') + rgb_im.save(filepath.rsplit('.', 1)[0] + ".jpg") + filepath = filepath.rsplit('.', 1)[0] + ".jpg" except ValueError as e: print("Error converting to JPG in " + title)