Fix bug where zero value for latitude/longitude causes error gh-171 (#176)

This commit is contained in:
Jaisen Mathai 2017-01-03 00:49:56 -08:00 committed by GitHub
parent 9fd03f0729
commit a48a2edb62
3 changed files with 24 additions and 9 deletions

View File

@ -86,22 +86,29 @@ class Media(Base):
# The lat/lon _keys array has an order of precedence.
# The first key is writable and we will give the writable
# key precence when reading.
direction_multiplier = 1
direction_multiplier = 1.0
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
# when self.set_gps_ref != True
if type == 'latitude' and key in self.latitude_keys and \
key in exif:
if type == 'latitude' and key in self.latitude_keys:
if self.latitude_ref_key in exif and \
exif[self.latitude_ref_key] == 'S':
direction_multiplier = -1
return exif[key] * direction_multiplier
elif type == 'longitude' and key in self.longitude_keys and \
key in exif:
direction_multiplier = -1.0
return this_coordinate * direction_multiplier
elif type == 'longitude' and key in self.longitude_keys:
if self.longitude_ref_key in exif and \
exif[self.longitude_ref_key] == 'W':
direction_multiplier = -1
return exif[key] * direction_multiplier
direction_multiplier = -1.0
return this_coordinate * direction_multiplier
return None

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@ -101,6 +101,14 @@ def test_get_coordinates_without_exif():
assert latitude is None, latitude
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():
photo = Photo(helper.get_file('plain.jpg'))
date_taken = photo.get_date_taken()