date_compare

find corresponding dates from location history and image exif data

Use exif explorer to build up a list of image metadata

import glob
path = 'sample-data/*.jpg'
images = glob.glob(path)
len(images)
2
image_list = extract_exif(images)
assert len(image_list) == 2
image_list[0].exif.get("datetime_original")
# note that some of these can be None, since some images are created by google photos
'2018:11:30 07:57:21'

Now we need to convert the to a timestamp the dates from exif


to_timestamp

 to_timestamp (date)
# testing to make sure we get the right value back
timestamp = to_timestamp(image_list[0].exif.get("datetime_original"))
timestamp
1543579041
timestamp2 = to_timestamp(image_list[-1].exif.get("datetime_original"))
timestamp2
1543547561

get_time_delta

 get_time_delta (a, b)

delta_to_minutes

 delta_to_minutes (delta)
results = get_time_delta(timestamp2, timestamp)
results
524
# quick test
assert(get_time_delta(timestamp2, timestamp)) == 524

Now lets pull some information from location history to compare

file_to_open = "sample-data/sample.json"

locations = get_locations(file_to_open)
assert len(locations) == 58
locations_w_gps = build_location_history(locations)
assert len(locations_w_gps) == 58
locations_w_gps[0]
Location(timestamp=1467216494, latitude=446549411, longitude=-635836042, accuracy=41)

Now lets come up with a bruteforce solution to finding the aligning dates from both datasets


get_smallest_deltas

 get_smallest_deltas (image_list, locations)
d = get_smallest_deltas(image_list, locations_w_gps)  
d
{0: 57, 1: 57}

Now we can take a peek at how close the date ranges between the image timestamps and location history timestamps are.


de_google_gps_info

 de_google_gps_info (d, image_list, locations)

convert_to_decimal

 convert_to_decimal (lat, long)
imgs_w_data = de_google_gps_info(d, image_list, locations_w_gps)
imgs_w_data[0]
ImageGPS(image_path='sample-data/sample.jpg', gps=(44.6551683, -63.5835479))

From here we can start associating the GPS data from the location history to the images that Google Photo’s has stripped.


write_gps_info_to_images

 write_gps_info_to_images (image_list, output_path)
# finally write out new files with GPS data merged in exif
output_path = '/tmp'
write_gps_info_to_images(imgs_w_data, output_path)

EXIF GPS fields for reference

exif:GPSAltitude=94940/11161
exif:GPSAltitudeRef=.
exif:GPSDestBearing=227653/2182
exif:GPSDestBearingRef=T
exif:GPSHPositioningError=33479/4096
exif:GPSImgDirection=227653/2182
exif:GPSImgDirectionRef=T
exif:GPSInfo=2272
exif:GPSLatitude=45/1, 30/1, 5110/100
exif:GPSLatitudeRef=N
exif:GPSLongitude=73/1, 31/1, 3981/100
exif:GPSLongitudeRef=W
exif:GPSSpeed=4744/18627
exif:GPSSpeedRef=K