forked from tykayn/mapillary_download
Get and write artist, camera make and model
This commit is contained in:
parent
17466a40b2
commit
98c850ac62
@ -42,10 +42,10 @@ def download(url, filepath, metadata=None):
|
|||||||
|
|
||||||
|
|
||||||
def get_single_image_data(image_id, mly_header):
|
def get_single_image_data(image_id, mly_header):
|
||||||
req_url = 'https://graph.mapillary.com/{}?fields=thumb_original_url,altitude,camera_type,captured_at,compass_angle,geometry,exif_orientation,sequence'.format(image_id)
|
req_url = 'https://graph.mapillary.com/{}?fields=creator,thumb_original_url,altitude,make,model,camera_type,captured_at,compass_angle,geometry,exif_orientation,sequence'.format(image_id)
|
||||||
r = session.get(req_url, headers=mly_header)
|
r = session.get(req_url, headers=mly_header)
|
||||||
data = r.json()
|
data = r.json()
|
||||||
#print(data)
|
print(data)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
@ -99,6 +99,9 @@ def write_exif(picture, img_metadata):
|
|||||||
# 'captured_at': 1603459736644, 'geometry': {'type': 'Point', 'coordinates': [2.5174596904057, 48.777089857534]}, 'id': '485924785946693'}
|
# 'captured_at': 1603459736644, 'geometry': {'type': 'Point', 'coordinates': [2.5174596904057, 48.777089857534]}, 'id': '485924785946693'}
|
||||||
|
|
||||||
with writer.Writer(picture) as image:
|
with writer.Writer(picture) as image:
|
||||||
|
image.add_artist(img_metadata)
|
||||||
|
image.add_camera_make(img_metadata)
|
||||||
|
image.add_camera_model(img_metadata)
|
||||||
image.add_datetimeoriginal(img_metadata)
|
image.add_datetimeoriginal(img_metadata)
|
||||||
image.add_lat_lon(img_metadata)
|
image.add_lat_lon(img_metadata)
|
||||||
image.add_altitude(img_metadata)
|
image.add_altitude(img_metadata)
|
||||||
@ -151,6 +154,9 @@ if __name__ == '__main__':
|
|||||||
path = os.path.join(path_destination, date_time_image_filename)
|
path = os.path.join(path_destination, date_time_image_filename)
|
||||||
img_metadata = writer.PictureMetadata(
|
img_metadata = writer.PictureMetadata(
|
||||||
capture_time = datetime.utcfromtimestamp(int(image_data['captured_at'])/1000),
|
capture_time = datetime.utcfromtimestamp(int(image_data['captured_at'])/1000),
|
||||||
|
artist = image_data['creator']['username'],
|
||||||
|
camera_make = image_data['make'],
|
||||||
|
camera_model = image_data['model'],
|
||||||
longitude = image_data['geometry']['coordinates'][0],
|
longitude = image_data['geometry']['coordinates'][0],
|
||||||
latitude = image_data['geometry']['coordinates'][1],
|
latitude = image_data['geometry']['coordinates'][1],
|
||||||
picture_type = PictureType("equirectangular") if image_data['camera_type'] == 'spherical' or image_data['camera_type'] == 'equirectangular' else PictureType("flat"),
|
picture_type = PictureType("equirectangular") if image_data['camera_type'] == 'spherical' or image_data['camera_type'] == 'equirectangular' else PictureType("flat"),
|
||||||
|
33
writer.py
33
writer.py
@ -20,6 +20,9 @@ tz_finder = timezonefinder.TimezoneFinder()
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class PictureMetadata:
|
class PictureMetadata:
|
||||||
|
artist: Optional[str] = None
|
||||||
|
camera_make: Optional[str] = None
|
||||||
|
camera_model: Optional[str] = None
|
||||||
capture_time: Optional[datetime] = None
|
capture_time: Optional[datetime] = None
|
||||||
longitude: Optional[float] = None
|
longitude: Optional[float] = None
|
||||||
latitude: Optional[float] = None
|
latitude: Optional[float] = None
|
||||||
@ -146,6 +149,32 @@ class Writer():
|
|||||||
self.updated_xmp["Xmp.GPano.ProjectionType"] = metadata.picture_type.value
|
self.updated_xmp["Xmp.GPano.ProjectionType"] = metadata.picture_type.value
|
||||||
self.updated_xmp["Xmp.GPano.UsePanoramaViewer"] = True
|
self.updated_xmp["Xmp.GPano.UsePanoramaViewer"] = True
|
||||||
|
|
||||||
|
def add_artist(self, metadata: PictureMetadata) -> None:
|
||||||
|
"""
|
||||||
|
Add image author in Exif Artist tag
|
||||||
|
"""
|
||||||
|
|
||||||
|
if metadata.artist is not None:
|
||||||
|
self.updated_exif["Exif.Image.Artist"] = ascii(metadata.artist).strip("'")
|
||||||
|
|
||||||
|
|
||||||
|
def add_camera_make(self, metadata: PictureMetadata) -> None:
|
||||||
|
"""
|
||||||
|
Add camera manufacture in Exif Make tag
|
||||||
|
"""
|
||||||
|
|
||||||
|
if metadata.camera_make is not None:
|
||||||
|
self.updated_exif["Exif.Image.Make"] = ascii(metadata.camera_make).strip("'")
|
||||||
|
|
||||||
|
|
||||||
|
def add_camera_model(self, metadata: PictureMetadata) -> None:
|
||||||
|
"""
|
||||||
|
Add camera model in Exif Model tag
|
||||||
|
"""
|
||||||
|
|
||||||
|
if metadata.camera_model is not None:
|
||||||
|
self.updated_exif["Exif.Image.Model"] = ascii(metadata.camera_model).strip("'")
|
||||||
|
|
||||||
def format_offset(self, offset: timedelta) -> str:
|
def format_offset(self, offset: timedelta) -> str:
|
||||||
"""Format offset for OffsetTimeOriginal. Format is like "+02:00" for paris offset
|
"""Format offset for OffsetTimeOriginal. Format is like "+02:00" for paris offset
|
||||||
>>> format_offset(timedelta(hours=5, minutes=45))
|
>>> format_offset(timedelta(hours=5, minutes=45))
|
||||||
@ -156,7 +185,6 @@ class Writer():
|
|||||||
offset_hour, remainer = divmod(offset.total_seconds(), 3600)
|
offset_hour, remainer = divmod(offset.total_seconds(), 3600)
|
||||||
return f"{'+' if offset_hour >= 0 else '-'}{int(abs(offset_hour)):02}:{int(remainer/60):02}"
|
return f"{'+' if offset_hour >= 0 else '-'}{int(abs(offset_hour)):02}:{int(remainer/60):02}"
|
||||||
|
|
||||||
|
|
||||||
def localize(self, naive_dt: datetime, metadata: PictureMetadata) -> datetime:
|
def localize(self, naive_dt: datetime, metadata: PictureMetadata) -> datetime:
|
||||||
"""
|
"""
|
||||||
Localize a datetime in the timezone of the picture
|
Localize a datetime in the timezone of the picture
|
||||||
@ -188,7 +216,6 @@ class Writer():
|
|||||||
|
|
||||||
return tz.localize(naive_dt)
|
return tz.localize(naive_dt)
|
||||||
|
|
||||||
|
|
||||||
def _from_dms(self, val: str) -> float:
|
def _from_dms(self, val: str) -> float:
|
||||||
"""Convert exif lat/lon represented as degre/minute/second into decimal
|
"""Convert exif lat/lon represented as degre/minute/second into decimal
|
||||||
>>> _from_dms("1/1 55/1 123020/13567")
|
>>> _from_dms("1/1 55/1 123020/13567")
|
||||||
@ -206,7 +233,6 @@ class Writer():
|
|||||||
|
|
||||||
return float(deg) + float(min) / 60 + float(sec) / 3600
|
return float(deg) + float(min) / 60 + float(sec) / 3600
|
||||||
|
|
||||||
|
|
||||||
def _to_dms(self, value: float) -> Tuple[int, int, float]:
|
def _to_dms(self, value: float) -> Tuple[int, int, float]:
|
||||||
"""Return degree/minute/seconds for a decimal
|
"""Return degree/minute/seconds for a decimal
|
||||||
>>> _to_dms(38.889469)
|
>>> _to_dms(38.889469)
|
||||||
@ -223,7 +249,6 @@ class Writer():
|
|||||||
|
|
||||||
return deg, int(min), round(sec, 8)
|
return deg, int(min), round(sec, 8)
|
||||||
|
|
||||||
|
|
||||||
def _to_exif_dms(self, value: float) -> str:
|
def _to_exif_dms(self, value: float) -> str:
|
||||||
"""Return degree/minute/seconds string formated for the exif metadata for a decimal
|
"""Return degree/minute/seconds string formated for the exif metadata for a decimal
|
||||||
>>> _to_exif_dms(38.889469)
|
>>> _to_exif_dms(38.889469)
|
||||||
|
Loading…
Reference in New Issue
Block a user