Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
Fixed "PermissionError anderbggo#14: Resolved an unhandled exception in script anderbggo#14" by moving the rename operation to after the image is saved.

Fixed "Failed to execute script 'window' due to unhandled exception: 'title' anderbggo#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.
  • Loading branch information
nils-simons committed Oct 10, 2024
1 parent 1a302c0 commit 8784f4a
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions files/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 8784f4a

Please sign in to comment.