Ejemplo n.º 1
0
def create_exif_from_metadata(path: str):
    """this method will generate exif data from metadata"""
    files = os.listdir(path)
    photos = []
    metadata_photos = []

    if not os.path.isfile(os.path.join(path, constants.METADATA_NAME)):
        LOGGER.warning("WARNING: No OSC metadata file found at %s", path)
        return

    for file_path in files:
        file_name, file_extension = os.path.splitext(file_path)
        if ("jpg" in file_extension or "jpeg" in file_extension) \
                and "thumb" not in file_name.lower():
            photo = Photo(os.path.join(path, file_path))
            if file_name.isdigit():
                photo.index = int(file_name)
            photos.append(photo)
        elif ".txt" in file_extension and constants.METADATA_NAME in file_path:
            metadata_file = file_path
            parser = MetadataManager.get_metadata_parser(path + "/" +
                                                         metadata_file)
            parser.start_new_reading()
            metadata_photos = parser.all_photos()

    if metadata_photos:
        photos.sort(
            key=lambda x: int(os.path.splitext(os.path.basename(x.path))[0]))
        metadata_photos.sort(key=lambda x: x.frame_index)
    else:
        LOGGER.warning("WARNING: NO metadata photos found at %s", path)
        return

    for photo in photos:
        metadata_photo: MetadataPhoto = None
        for tmp_photo in metadata_photos:
            if int(tmp_photo.frame_index) == photo.index:
                metadata_photo = tmp_photo
                break
        if not metadata_photo:
            continue
        __metadata_photo_to_photo(metadata_photo, photo)

    for photo in photos:
        tags = exif_processing.create_required_gps_tags(
            photo.gps_timestamp, photo.latitude, photo.longitude)
        exif_processing.add_optional_gps_tags(tags, photo.gps_speed,
                                              photo.gps_altitude,
                                              photo.gps_compass)
        exif_processing.add_gps_tags(photo.path, tags)
Ejemplo n.º 2
0
 def _photo_from_path(cls, path) -> Photo:
     photo = Photo(path)
     tags_data = exif_processing.all_tags(photo.path)
     # required data
     photo.gps_timestamp = exif_processing.gps_timestamp(tags_data)
     photo.latitude = exif_processing.gps_latitude(tags_data)
     photo.longitude = exif_processing.gps_longitude(tags_data)
     if not photo.latitude or \
             not photo.longitude or \
             not photo.gps_timestamp:
         return None
     # optional data
     photo.exif_timestamp = exif_processing.timestamp(tags_data)
     photo.gps_speed = exif_processing.gps_speed(tags_data)
     photo.gps_altitude = exif_processing.gps_altitude(tags_data)
     photo.gps_compass = exif_processing.gps_compass(tags_data)
     return photo
Ejemplo n.º 3
0
    def _photo_from_path(cls, path) -> Photo:
        photo = Photo(path)
        tags_data = exif_processing.all_tags(photo.path)

        # required gps timestamp or exif timestamp
        photo.gps_timestamp = exif_processing.gps_timestamp(tags_data)
        photo.exif_timestamp = exif_processing.timestamp(tags_data)
        if not photo.gps_timestamp and photo.exif_timestamp:
            photo.gps_timestamp = photo.exif_timestamp

        # required latitude and longitude
        photo.latitude = exif_processing.gps_latitude(tags_data)
        photo.longitude = exif_processing.gps_longitude(tags_data)
        if not photo.latitude or \
                not photo.longitude or \
                not photo.gps_timestamp:
            return None

        # optional data
        photo.gps_speed = exif_processing.gps_speed(tags_data)
        photo.gps_altitude = exif_processing.gps_altitude(tags_data)
        photo.gps_compass = exif_processing.gps_compass(tags_data)
        LOGGER.debug("lat/lon: %f/%f", photo.latitude, photo.longitude)
        return photo
Ejemplo n.º 4
0
def metadata_photo_to_photo(metadata_photo: MetadataPhoto, photo: Photo):
    if metadata_photo.gps.latitude:
        photo.latitude = float(metadata_photo.gps.latitude)
    if metadata_photo.gps.longitude:
        photo.longitude = float(metadata_photo.gps.longitude)
    if metadata_photo.gps.speed:
        photo.gps_speed = round(float(metadata_photo.gps.speed) * 3.6)
    if metadata_photo.gps.altitude:
        photo.gps_altitude = float(metadata_photo.gps.altitude)
    if metadata_photo.frame_index:
        photo.index = int(metadata_photo.frame_index)
    if metadata_photo.timestamp:
        photo.gps_timestamp = float(metadata_photo.timestamp)
def metadata_photo_to_photo(metadata_photo: MetadataPhoto, photo: Photo):
    if metadata_photo.gps.latitude:
        photo.latitude = float(metadata_photo.gps.latitude)
    if metadata_photo.gps.longitude:
        photo.longitude = float(metadata_photo.gps.longitude)
    if metadata_photo.gps.speed:
        photo.gps_speed = round(float(metadata_photo.gps.speed) * 3.6)
    if metadata_photo.gps.altitude:
        photo.gps_altitude = float(metadata_photo.gps.altitude)
    if metadata_photo.frame_index:
        photo.index = int(metadata_photo.frame_index)
    if metadata_photo.timestamp:
        photo.gps_timestamp = float(metadata_photo.timestamp)
    def _photo_from_path(cls, path) -> Photo:
        photo = Photo(path)
        tags_data = exif_processing.all_tags(photo.path)

        # required gps timestamp or exif timestamp
        photo.gps_timestamp = exif_processing.gps_timestamp(tags_data)
        photo.exif_timestamp = exif_processing.timestamp(tags_data)
        if not photo.gps_timestamp and photo.exif_timestamp:
            photo.gps_timestamp = photo.exif_timestamp

        # required latitude and longitude
        photo.latitude = exif_processing.gps_latitude(tags_data)
        photo.longitude = exif_processing.gps_longitude(tags_data)
        if not photo.latitude or \
                not photo.longitude or \
                not photo.gps_timestamp:
            return None

        # optional data
        photo.gps_speed = exif_processing.gps_speed(tags_data)
        photo.gps_altitude = exif_processing.gps_altitude(tags_data)
        photo.gps_compass = exif_processing.gps_compass(tags_data)
        LOGGER.debug("lat/lon: %f/%f", photo.latitude, photo.longitude)
        return photo
Ejemplo n.º 7
0
 def _photo_from_path(cls, path) -> Photo:
     photo = Photo(path)
     return photo
Ejemplo n.º 8
0
    def _photo_from_path(cls, path) -> Optional[Photo]:
        photo = Photo(path)
        exif_parser = ExifParser.valid_parser(path, Local())
        photo_metadata: PhotoMetadata = exif_parser.next_item_with_class(PhotoMetadata)

        if photo_metadata is None:
            return None

        # required gps timestamp or exif timestamp
        photo.gps_timestamp = photo_metadata.gps.timestamp
        photo.exif_timestamp = photo_metadata.timestamp
        if not photo.gps_timestamp and photo.exif_timestamp:
            photo.gps_timestamp = photo.exif_timestamp

        # required latitude and longitude
        photo.latitude = photo_metadata.gps.latitude
        photo.longitude = photo_metadata.gps.longitude
        if not photo.latitude or \
                not photo.longitude or \
                not photo.gps_timestamp:
            return None

        # optional data
        photo.gps_speed = photo_metadata.gps.speed
        photo.gps_altitude = photo_metadata.gps.altitude
        photo.gps_compass = photo_metadata.compass.compass

        try:
            xmp_parser = XMPParser.valid_parser(path, Local())
            camera_params: CameraParameters = xmp_parser.next_item_with_class(CameraParameters)
            if camera_params is not None:
                photo.fov = camera_params.h_fov
                photo.projection = camera_params.projection
        except Exception:
            pass

        LOGGER.debug("lat/lon: %f/%f", photo.latitude, photo.longitude)
        return photo