Fix bug where zero value for latitude/longitude causes error gh-171 (#176)
This commit is contained in:
parent
9fd03f0729
commit
a48a2edb62
|
@ -86,22 +86,29 @@ class Media(Base):
|
||||||
# The lat/lon _keys array has an order of precedence.
|
# The lat/lon _keys array has an order of precedence.
|
||||||
# The first key is writable and we will give the writable
|
# The first key is writable and we will give the writable
|
||||||
# key precence when reading.
|
# key precence when reading.
|
||||||
direction_multiplier = 1
|
direction_multiplier = 1.0
|
||||||
for key in self.latitude_keys + self.longitude_keys:
|
for key in self.latitude_keys + self.longitude_keys:
|
||||||
|
if key not in exif:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Cast coordinate to a float due to a bug in exiftool's
|
||||||
|
# -json output format.
|
||||||
|
# https://github.com/jmathai/elodie/issues/171
|
||||||
|
# http://u88.n24.queensu.ca/exiftool/forum/index.php/topic,7952.0.html #noqa
|
||||||
|
this_coordinate = float(exif[key])
|
||||||
|
|
||||||
# TODO: verify that we need to check ref key
|
# TODO: verify that we need to check ref key
|
||||||
# when self.set_gps_ref != True
|
# when self.set_gps_ref != True
|
||||||
if type == 'latitude' and key in self.latitude_keys and \
|
if type == 'latitude' and key in self.latitude_keys:
|
||||||
key in exif:
|
|
||||||
if self.latitude_ref_key in exif and \
|
if self.latitude_ref_key in exif and \
|
||||||
exif[self.latitude_ref_key] == 'S':
|
exif[self.latitude_ref_key] == 'S':
|
||||||
direction_multiplier = -1
|
direction_multiplier = -1.0
|
||||||
return exif[key] * direction_multiplier
|
return this_coordinate * direction_multiplier
|
||||||
elif type == 'longitude' and key in self.longitude_keys and \
|
elif type == 'longitude' and key in self.longitude_keys:
|
||||||
key in exif:
|
|
||||||
if self.longitude_ref_key in exif and \
|
if self.longitude_ref_key in exif and \
|
||||||
exif[self.longitude_ref_key] == 'W':
|
exif[self.longitude_ref_key] == 'W':
|
||||||
direction_multiplier = -1
|
direction_multiplier = -1.0
|
||||||
return exif[key] * direction_multiplier
|
return this_coordinate * direction_multiplier
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
|
@ -101,6 +101,14 @@ def test_get_coordinates_without_exif():
|
||||||
assert latitude is None, latitude
|
assert latitude is None, latitude
|
||||||
assert longitude is None, longitude
|
assert longitude is None, longitude
|
||||||
|
|
||||||
|
def test_get_coordinates_with_zero_coordinate():
|
||||||
|
photo = Photo(helper.get_file('with-location-zero-coordinate.jpg'))
|
||||||
|
latitude = photo.get_coordinate('latitude')
|
||||||
|
longitude = photo.get_coordinate('longitude')
|
||||||
|
|
||||||
|
assert helper.isclose(latitude,51.55325), latitude
|
||||||
|
assert helper.isclose(longitude,-0.00417777777778), longitude
|
||||||
|
|
||||||
def test_get_date_taken():
|
def test_get_date_taken():
|
||||||
photo = Photo(helper.get_file('plain.jpg'))
|
photo = Photo(helper.get_file('plain.jpg'))
|
||||||
date_taken = photo.get_date_taken()
|
date_taken = photo.get_date_taken()
|
||||||
|
|
Loading…
Reference in New Issue