From 6ab0ad7e8625304ae321ed6fdd3a8a96a5f5236e Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Fri, 3 Jul 2020 09:04:23 -0700 Subject: [PATCH] Added GPS location to XMP sidecar, closes #175 --- osxphotos/_version.py | 2 +- osxphotos/photoinfo/_photoinfo_export.py | 1 - osxphotos/templates/xmp_sidecar.mako | 19 +++- tests/test_export_catalina_10_15_1.py | 100 ++++++++++++++++-- ...xport_keyword_template_catalina_10_15_4.py | 9 +- tests/test_export_mojave_10_14_6.py | 19 ++-- 6 files changed, 125 insertions(+), 25 deletions(-) diff --git a/osxphotos/_version.py b/osxphotos/_version.py index d5a09a87..e522448a 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.30.3" +__version__ = "0.30.4" diff --git a/osxphotos/photoinfo/_photoinfo_export.py b/osxphotos/photoinfo/_photoinfo_export.py index b4ee0c0b..6cb42324 100644 --- a/osxphotos/photoinfo/_photoinfo_export.py +++ b/osxphotos/photoinfo/_photoinfo_export.py @@ -1103,7 +1103,6 @@ def _exiftool_json_sidecar( lat_str, lon_str = dd_to_dms_str(lat, lon) exif["EXIF:GPSLatitude"] = lat_str exif["EXIF:GPSLongitude"] = lon_str - exif["Composite:GPSPosition"] = f"{lat_str}, {lon_str}" lat_ref = "North" if lat >= 0 else "South" lon_ref = "East" if lon >= 0 else "West" exif["EXIF:GPSLatitudeRef"] = lat_ref diff --git a/osxphotos/templates/xmp_sidecar.mako b/osxphotos/templates/xmp_sidecar.mako index 3b9badb2..7f081523 100644 --- a/osxphotos/templates/xmp_sidecar.mako +++ b/osxphotos/templates/xmp_sidecar.mako @@ -71,6 +71,15 @@ % endif +<%def name="gps_info(latitude, longitude)"> + % if latitude is not None and longitude is not None: + ${"E" if longitude >= 0 else "W"} + ${abs(longitude)} + ${abs(latitude)} + ${"N" if latitude >= 0 else "S"} + % endif + + @@ -82,18 +91,22 @@ ${dc_subject(subjects)} ${dc_datecreated(photo.date)} - ${iptc_personinimage(persons)} - ${dk_tagslist(keywords)} - ${adobe_createdate(photo.date)} ${adobe_modifydate(photo.date)} + + ${gps_info(*photo.location)} + \ No newline at end of file diff --git a/tests/test_export_catalina_10_15_1.py b/tests/test_export_catalina_10_15_1.py index 25e4477c..826a8969 100644 --- a/tests/test_export_catalina_10_15_1.py +++ b/tests/test_export_catalina_10_15_1.py @@ -455,7 +455,6 @@ def test_exiftool_json_sidecar(): "XMP:Subject": ["London 2018", "St. James\'s Park", "England", "United Kingdom", "UK", "London"], "EXIF:GPSLatitude": "51 deg 30\' 12.86\\" N", "EXIF:GPSLongitude": "0 deg 7\' 54.50\\" W", - "Composite:GPSPosition": "51 deg 30\' 12.86\\" N, 0 deg 7\' 54.50\\" W", "EXIF:GPSLatitudeRef": "North", "EXIF:GPSLongitudeRef": "West", "EXIF:DateTimeOriginal": "2018:10:13 09:18:12", "EXIF:OffsetTimeOriginal": "-04:00", @@ -586,7 +585,7 @@ def test_xmp_sidecar(): 2018-09-28T15:35:49.063000-04:00 - @@ -595,7 +594,7 @@ def test_xmp_sidecar(): - @@ -603,10 +602,13 @@ def test_xmp_sidecar(): - 2018-09-28T15:35:49 2018-09-28T15:35:49 + + """ @@ -647,7 +649,7 @@ def test_xmp_sidecar_use_persons_keyword(): 2018-09-28T15:35:49.063000-04:00 - @@ -656,7 +658,7 @@ def test_xmp_sidecar_use_persons_keyword(): - @@ -666,11 +668,14 @@ def test_xmp_sidecar_use_persons_keyword(): - 2018-09-28T15:35:49 2018-09-28T15:35:49 + + """ @@ -710,7 +715,7 @@ def test_xmp_sidecar_use_albums_keyword(): 2018-09-28T15:35:49.063000-04:00 - @@ -719,7 +724,7 @@ def test_xmp_sidecar_use_albums_keyword(): - @@ -729,11 +734,14 @@ def test_xmp_sidecar_use_albums_keyword(): - 2018-09-28T15:35:49 2018-09-28T15:35:49 + + """ @@ -746,3 +754,75 @@ def test_xmp_sidecar_use_albums_keyword(): sorted(xmp_expected_lines), sorted(xmp_got_lines) ): assert line_expected == line_got + + +def test_xmp_sidecar_gps(): + """ Test export XMP sidecar with GPS info """ + import osxphotos + + photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) + photos = photosdb.photos(uuid=[UUID_DICT["location"]]) + + xmp_expected = """ + + + + + + St. James's Park + + + + UK + England + London + United Kingdom + London 2018 + St. James's Park + + + 2018-10-13T09:18:12.501000-04:00 + + + + + + + UK + England + London + United Kingdom + London 2018 + St. James's Park + + + + + 2018-10-13T09:18:12 + 2018-10-13T09:18:12 + + + W + 0.1318055 + 51.50357167 + N + + +""" + + xmp_expected_lines = [line.strip() for line in xmp_expected.split("\n")] + + xmp_got = photos[0]._xmp_sidecar() + xmp_got_lines = [line.strip() for line in xmp_got.split("\n")] + + for line_expected, line_got in zip( + sorted(xmp_expected_lines), sorted(xmp_got_lines) + ): + assert line_expected == line_got + diff --git a/tests/test_export_keyword_template_catalina_10_15_4.py b/tests/test_export_keyword_template_catalina_10_15_4.py index 9d7633ec..c4737a16 100644 --- a/tests/test_export_keyword_template_catalina_10_15_4.py +++ b/tests/test_export_keyword_template_catalina_10_15_4.py @@ -178,7 +178,7 @@ def test_xmp_sidecar_keyword_template(): 2018-09-28T15:35:49.063000-04:00 - @@ -187,7 +187,7 @@ def test_xmp_sidecar_keyword_template(): - @@ -198,11 +198,14 @@ def test_xmp_sidecar_keyword_template(): - 2018-09-28T15:35:49 2018-09-28T15:35:49 + + """ diff --git a/tests/test_export_mojave_10_14_6.py b/tests/test_export_mojave_10_14_6.py index ee9810f3..59b45977 100644 --- a/tests/test_export_mojave_10_14_6.py +++ b/tests/test_export_mojave_10_14_6.py @@ -380,7 +380,6 @@ def test_exiftool_json_sidecar(): "XMP:Subject": ["London 2018", "St. James\'s Park", "England", "United Kingdom", "UK", "London"], "EXIF:GPSLatitude": "51 deg 30\' 12.86\\" N", "EXIF:GPSLongitude": "0 deg 7\' 54.50\\" W", - "Composite:GPSPosition": "51 deg 30\' 12.86\\" N, 0 deg 7\' 54.50\\" W", "EXIF:GPSLatitudeRef": "North", "EXIF:GPSLongitudeRef": "West", "EXIF:DateTimeOriginal": "2018:10:13 09:18:12", "EXIF:OffsetTimeOriginal": "-04:00", @@ -431,7 +430,7 @@ def test_xmp_sidecar(): 2018-09-28T15:35:49.063000-04:00 - @@ -440,7 +439,7 @@ def test_xmp_sidecar(): - @@ -448,11 +447,14 @@ def test_xmp_sidecar(): - 2018-09-28T15:35:49 2018-09-28T15:35:49 + + """ @@ -490,7 +492,7 @@ def test_xmp_sidecar_keyword_template(): 2018-09-28T15:35:49.063000-04:00 - @@ -499,7 +501,7 @@ def test_xmp_sidecar_keyword_template(): - @@ -510,11 +512,14 @@ def test_xmp_sidecar_keyword_template(): - 2018-09-28T15:35:49 2018-09-28T15:35:49 + + """