def extract_capture_time()

in mapillary_tools/exif_read.py [0:0]


    def extract_capture_time(self) -> Optional[datetime.datetime]:
        """
        Extract capture time from EXIF
        return a datetime object
        TODO: handle GPS DateTime
        """
        time_string = exif_datetime_fields()[0]
        capture_time, time_field = self._extract_alternative_fields(
            time_string, default=None, field_type=str
        )
        if time_field in exif_gps_date_fields()[0]:
            return self.extract_gps_time()

        if capture_time is None:
            # try interpret the filename
            basename, _ = os.path.splitext(os.path.basename(self.filename))
            try:
                return datetime.datetime.strptime(
                    basename + "000", "%Y_%m_%d_%H_%M_%S_%f"
                )
            except ValueError:
                return None
        else:
            capture_time = capture_time.replace(" ", "_")
            capture_time = capture_time.replace(":", "_")
            capture_time = capture_time.replace(".", "_")
            capture_time = capture_time.replace("-", "_")
            capture_time = capture_time.replace(",", "_")
            capture_time = "_".join(
                [ts for ts in capture_time.split("_") if ts.isdigit()]
            )
            capture_time_obj, has_subseconds = format_time(capture_time)
            if not has_subseconds:
                sub_sec = self._extract_subsec()
                # Fix spaces in subsec in gopro
                # See https://github.com/mapillary/mapillary_tools/issues/388#issuecomment-860198046
                # and https://community.gopro.com/t5/Cameras/subsecond-timestamp-bug/m-p/1057505
                if sub_sec.startswith(" "):
                    make = self.extract_make()
                    if make is not None and make.lower() == "gopro":
                        sub_sec = sub_sec.replace(" ", "0")
                capture_time_obj = capture_time_obj + datetime.timedelta(
                    seconds=float("0." + sub_sec)
                )
            return capture_time_obj