Explorar o código

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

Fabian Peter Hammerle hai 10 meses
pai
achega
cc438eda84
Modificáronse 1 ficheiros con 3 adicións e 1 borrados
  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(