Browse Source

function "read_exif_datetime_original": return None when tag is not available (instead of raising "KeyError: 'EXIF DateTimeOriginal'")

Fabian Peter Hammerle 10 tháng trước cách đây
mục cha
commit
cc438eda84
1 tập tin đã thay đổi với 3 bổ sung1 xóa
  1. 3 1
      profile_default/startup/init.py

+ 3 - 1
profile_default/startup/init.py

@@ -45,9 +45,11 @@ def numpy_array_from_file(
     return numpy.frombuffer(path.read_bytes(), dtype=dtype)
 
 
-def read_exif_datetime_original(path: str) -> datetime.datetime:
+def read_exif_datetime_original(path: str) -> typing.Optional[datetime.datetime]:
     with pathlib.Path(path).open("rb") as file:
         tags = exifread.process_file(file)
+        if "EXIF DateTimeOriginal" not in tags:
+            return None
         return dateutil.parser.parse(
             # https://web.archive.org/web/20240609164044/https://github.com/dateutil/dateutil/issues/271
             datetime.datetime.strptime(