diff --git a/elodie/media/media.py b/elodie/media/media.py index dce4ef3..788b670 100644 --- a/elodie/media/media.py +++ b/elodie/media/media.py @@ -11,6 +11,7 @@ are used to represent the actual files. from __future__ import print_function import os +import six # load modules from elodie.external.pyexiftool import ExifTool @@ -88,6 +89,11 @@ class Media(Base): for key in self.latitude_keys + self.longitude_keys: if key not in exif: continue + if isinstance(exif[key], six.string_types) and len(exif[key]) == 0: + # If exiftool GPS output is empty, the data returned will be a str + # with 0 length. + # https://github.com/jmathai/elodie/issues/354 + continue # Cast coordinate to a float due to a bug in exiftool's # -json output format. diff --git a/elodie/tests/files/with-null-coordinates.jpg b/elodie/tests/files/with-null-coordinates.jpg new file mode 100755 index 0000000..aa623c8 Binary files /dev/null and b/elodie/tests/files/with-null-coordinates.jpg differ diff --git a/elodie/tests/media/photo_test.py b/elodie/tests/media/photo_test.py index 8ca389b..08019cb 100644 --- a/elodie/tests/media/photo_test.py +++ b/elodie/tests/media/photo_test.py @@ -113,6 +113,14 @@ def test_get_coordinates_with_zero_coordinate(): assert helper.isclose(latitude,51.55325), latitude assert helper.isclose(longitude,-0.00417777777778), longitude +def test_get_coordinates_with_null_coordinate(): + photo = Photo(helper.get_file('with-null-coordinates.jpg')) + latitude = photo.get_coordinate('latitude') + longitude = photo.get_coordinate('longitude') + + assert latitude is None, latitude + assert longitude is None, longitude + def test_get_date_taken(): photo = Photo(helper.get_file('plain.jpg')) date_taken = photo.get_date_taken()