From 60d96a8f563882fba2365a6ab58c1276725eedaa Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Tue, 25 Aug 2020 21:46:07 -0700 Subject: [PATCH] Added photoshop:SidecarForExtension to XMP, partial fix for #210 --- osxphotos/_version.py | 2 +- osxphotos/photoinfo/_photoinfo_export.py | 12 ++++++++---- osxphotos/templates/xmp_sidecar.mako | 9 +++++++++ tests/test_export_catalina_10_15_1.py | 4 ++++ .../test_export_keyword_template_catalina_10_15_4.py | 1 + tests/test_export_mojave_10_14_6.py | 2 ++ 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 74d57efe..80d20f8d 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.33.5" +__version__ = "0.33.6" diff --git a/osxphotos/photoinfo/_photoinfo_export.py b/osxphotos/photoinfo/_photoinfo_export.py index 71b0e353..945d7f28 100644 --- a/osxphotos/photoinfo/_photoinfo_export.py +++ b/osxphotos/photoinfo/_photoinfo_export.py @@ -629,7 +629,7 @@ def export2( logging.debug(f"Skipping missing RAW photo for {filename}") else: # use_photo_export - exported = [] + exported = [] # export live_photo .mov file? live_photo = True if live_photo and self.live_photo else False if edited: @@ -677,7 +677,7 @@ def export2( exported_files.extend(exported) if update: update_new_files.extend(exported) - + else: logging.warning( f"Error exporting photo {self.uuid} to {dest} with use_photos_export" @@ -1127,10 +1127,13 @@ def _xmp_sidecar( keyword_template: (list of strings); list of template strings to render as keywords description_template: string; optional template string that will be rendered for use as photo description """ - # TODO: add additional fields to XMP file? - xmp_template = Template(filename=os.path.join(_TEMPLATE_DIR, _XMP_TEMPLATE_NAME)) + if self.path is not None: + extension = pathlib.Path(self.path).suffix[1:].upper() + else: + extension = None + if description_template is not None: description = self.render_template( description_template, expand_inplace=True, inplace_sep=", " @@ -1199,6 +1202,7 @@ def _xmp_sidecar( keywords=keyword_list, persons=person_list, subjects=subject_list, + extension=extension, ) # remove extra lines that mako inserts from template diff --git a/osxphotos/templates/xmp_sidecar.mako b/osxphotos/templates/xmp_sidecar.mako index 7f081523..f34c1b9b 100644 --- a/osxphotos/templates/xmp_sidecar.mako +++ b/osxphotos/templates/xmp_sidecar.mako @@ -1,5 +1,13 @@ +<%def name="photoshop_sidecar_for_extension(extension)"> + % if extension is None: + + % else: + ${extension} + % endif + + <%def name="dc_description(desc)"> % if desc is None: @@ -86,6 +94,7 @@ + ${photoshop_sidecar_for_extension(extension)} ${dc_description(description)} ${dc_title(photo.title)} ${dc_subject(subjects)} diff --git a/tests/test_export_catalina_10_15_1.py b/tests/test_export_catalina_10_15_1.py index 462be0f8..6293e067 100644 --- a/tests/test_export_catalina_10_15_1.py +++ b/tests/test_export_catalina_10_15_1.py @@ -596,6 +596,7 @@ def test_xmp_sidecar(): + JPEG Girls with pumpkins Can we carry this? @@ -660,6 +661,7 @@ def test_xmp_sidecar_use_persons_keyword(): + JPEG Girls with pumpkins Can we carry this? @@ -726,6 +728,7 @@ def test_xmp_sidecar_use_albums_keyword(): + JPEG Girls with pumpkins Can we carry this? @@ -793,6 +796,7 @@ def test_xmp_sidecar_gps(): + JPEG St. James's Park 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 c4737a16..3d4718a2 100644 --- a/tests/test_export_keyword_template_catalina_10_15_4.py +++ b/tests/test_export_keyword_template_catalina_10_15_4.py @@ -166,6 +166,7 @@ def test_xmp_sidecar_keyword_template(): + JPEG Girls with pumpkins Can we carry this? diff --git a/tests/test_export_mojave_10_14_6.py b/tests/test_export_mojave_10_14_6.py index 59b45977..66406c75 100644 --- a/tests/test_export_mojave_10_14_6.py +++ b/tests/test_export_mojave_10_14_6.py @@ -418,6 +418,7 @@ def test_xmp_sidecar(): + JPG Girls with pumpkins Can we carry this? @@ -480,6 +481,7 @@ def test_xmp_sidecar_keyword_template(): + JPG Girls with pumpkins Can we carry this?