Skip to content

Commit

Permalink
Use a different instance of exiftool, when using -struct
Browse files Browse the repository at this point in the history
  • Loading branch information
derneuere committed Jun 16, 2023
1 parent 171a5d1 commit 87a24d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
14 changes: 9 additions & 5 deletions api/models/photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,12 @@ def _extract_video_length(self, commit=True):
(video_length,) = get_metadata(
self.main_file.path, tags=[Tags.QUICKTIME_DURATION], try_sidecar=True
)
logger.debug(f"Extracted rating for {self.main_file.path}: {video_length}")
self.video_length = video_length
logger.debug(
f"Extracted video length for {self.main_file.path}: {video_length}"
)
if video_length and isinstance(video_length, numbers.Number):
self.video_length = video_length

if commit:
self.save()

Expand Down Expand Up @@ -564,7 +568,7 @@ def _extract_exif_data(self, commit=True):
self.shutter_speed = str(Fraction(shutter_speed).limit_denominator(1000))
if camera and isinstance(camera, str):
self.camera = camera
if lens and isinstance(camera, str):
if lens and isinstance(lens, str):
self.lens = lens
if width and isinstance(width, numbers.Number):
self.width = width
Expand Down Expand Up @@ -606,7 +610,7 @@ def _extract_faces(self, second_try=False):
)

(region_info,) = get_metadata(
self.main_file.path, tags=[Tags.REGION_INFO], try_sidecar=True
self.main_file.path, tags=[Tags.REGION_INFO], try_sidecar=True, struct=True
)

if region_info:
Expand Down Expand Up @@ -680,7 +684,7 @@ def _extract_faces(self, second_try=False):
try:
face_locations = face_recognition.face_locations(image)
except Exception:
logger.debug(
logger.info(
f"Can't extract face information on photo: {self.main_file.path}"
)

Expand Down
8 changes: 6 additions & 2 deletions api/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def get_sidecar_files_in_priority_order(media_file):
]


exiftool_instance = exiftool.ExifTool(common_args=["-struct"])
exiftool_instance_struct = exiftool.ExifTool(common_args=["-struct"])
exiftool_instance = exiftool.ExifTool()


def _get_existing_metadata_files_reversed(media_file, include_sidecar_files):
Expand All @@ -106,17 +107,20 @@ def _get_existing_metadata_files_reversed(media_file, include_sidecar_files):
return [media_file]


def get_metadata(media_file, tags, try_sidecar=True):
def get_metadata(media_file, tags, try_sidecar=True, struct=False):
"""
Get values for each metadata tag in *tags* from *media_file*.
If *try_sidecar* is `True`, use the value set in any XMP sidecar file
stored alongside *media_file*.
If *struct* is `True`, use the exiftool instance which returns structured data
Returns a list with the value of each tag in *tags* or `None` if the
tag was not found.
"""
et = exiftool_instance
if struct:
et = exiftool_instance_struct
terminate_et = False
if not et.running:
et.start()
Expand Down

0 comments on commit 87a24d1

Please sign in to comment.