Simplified build_captures_from_exif
This commit is contained in:
parent
c58827a0cf
commit
6c51da5394
1 changed files with 31 additions and 37 deletions
|
|
@ -60,11 +60,9 @@ def build_captures_from_exif(capture_path):
|
||||||
|
|
||||||
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)
|
capture = capture_from_path(f)
|
||||||
if exif:
|
if capture:
|
||||||
capture = capture_from_exif(f, exif)
|
captures[capture.id] = capture
|
||||||
if capture:
|
|
||||||
captures[capture.id] = capture
|
|
||||||
else:
|
else:
|
||||||
logging.error("Invalid data at {}. Skipping.".format(f))
|
logging.error("Invalid data at {}. Skipping.".format(f))
|
||||||
|
|
||||||
|
|
@ -73,44 +71,40 @@ def build_captures_from_exif(capture_path):
|
||||||
return captures
|
return captures
|
||||||
|
|
||||||
|
|
||||||
def capture_from_exif(path, exif_dict):
|
def capture_from_path(path):
|
||||||
"""
|
exif_dict = pull_usercomment_dict(path)
|
||||||
Creates an instance of CaptureObject from a dictionary of capture information.
|
if exif_dict:
|
||||||
This is used when reloading the API server, to restore captures created in the
|
# Create a placeholder capture
|
||||||
previous session.
|
capture = CaptureObject(filepath=path)
|
||||||
|
|
||||||
Args:
|
# Build file path information
|
||||||
path (str): Path to image file
|
capture.split_file_path(capture.file)
|
||||||
exif_dict (dict): Dictionary containing capture information
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Create a placeholder capture
|
# Image metadata
|
||||||
capture = CaptureObject(filepath=path)
|
try:
|
||||||
|
image_metadata = exif_dict.pop("image")
|
||||||
|
except KeyError:
|
||||||
|
logging.error(
|
||||||
|
"Unable to obtain valid 2.0 OpenFlexure metadata from file %s", path
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
|
||||||
# Build file path information
|
# Populate capture parameters
|
||||||
capture.split_file_path(capture.file)
|
capture.id = image_metadata.get("id")
|
||||||
|
capture.datetime = dateutil.parser.isoparse(
|
||||||
# Image metadata
|
image_metadata.get("acquisitionDate")
|
||||||
try:
|
|
||||||
image_metadata = exif_dict.pop("image")
|
|
||||||
except KeyError:
|
|
||||||
logging.error(
|
|
||||||
"Unable to obtain valid 2.0 OpenFlexure metadata from file %s", path
|
|
||||||
)
|
)
|
||||||
|
capture.format = image_metadata.get("format")
|
||||||
|
capture.tags = image_metadata.get("tags")
|
||||||
|
capture.annotations = image_metadata.get("annotations")
|
||||||
|
|
||||||
|
# Since we popped the "image" key, we dump whatever is left in _metadata
|
||||||
|
capture.set_metadata(exif_dict)
|
||||||
|
|
||||||
|
return capture
|
||||||
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Populate capture parameters
|
|
||||||
capture.id = image_metadata.get("id")
|
|
||||||
capture.datetime = dateutil.parser.isoparse(image_metadata.get("acquisitionDate"))
|
|
||||||
capture.format = image_metadata.get("format")
|
|
||||||
capture.tags = image_metadata.get("tags")
|
|
||||||
capture.annotations = image_metadata.get("annotations")
|
|
||||||
|
|
||||||
# Since we popped the "image" key, we dump whatever is left in _metadata
|
|
||||||
capture.set_metadata(exif_dict)
|
|
||||||
|
|
||||||
return capture
|
|
||||||
|
|
||||||
|
|
||||||
class CaptureObject(object):
|
class CaptureObject(object):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue