Skip loading invalid captures into array

This commit is contained in:
Joel Collins 2019-05-29 09:32:14 +01:00
parent 2c4fa4aead
commit c107125377

View file

@ -49,11 +49,11 @@ def pull_usercomment_dict(filepath):
exif_dict = piexif.load(filepath) exif_dict = piexif.load(filepath)
except InvalidImageDataError: except InvalidImageDataError:
logging.error("Invalid data at {}. Skipping.".format(filepath)) logging.error("Invalid data at {}. Skipping.".format(filepath))
return {} return None
if 'Exif' in exif_dict and 37510 in exif_dict['Exif']: if 'Exif' in exif_dict and 37510 in exif_dict['Exif']:
return yaml.load(exif_dict['Exif'][37510].decode()) return yaml.load(exif_dict['Exif'][37510].decode())
else: else:
return {} return None
def make_file_list(directory, formats): def make_file_list(directory, formats):
@ -76,8 +76,11 @@ def build_captures_from_exif():
for f in files: for f in files:
logging.debug("Reloading capture {}...".format(f)) logging.debug("Reloading capture {}...".format(f))
exif = pull_usercomment_dict(f) exif = pull_usercomment_dict(f)
capture = capture_from_exif(f, exif) if exif:
captures.append(capture) capture = capture_from_exif(f, exif)
captures.append(capture)
else:
logging.error("Invalid data at {}. Skipping.".format(f))
logging.info("{} capture files successfully reloaded".format(len(captures))) logging.info("{} capture files successfully reloaded".format(len(captures)))