Check that an XMP property exists before overwriting.
@@ -44,17 +44,20 @@ def embed_xmp_bytes(image: io.BytesIO, work_properties):
xmp.register_namespace(XMP_NS_CC, 'cc')
xmp.set_property(XMP_NS_CC, 'license', work_properties['license_url'])
if 'creator' in work_properties:
+ if not xmp.does_property_exist(XMP_NS_CC, 'attributionName'):
xmp.set_property(
XMP_NS_CC, 'attributionName', work_properties['creator']
)
if 'work_landing_page' in work_properties:
+ if not xmp.does_property_exist(XMP_NS_CC, 'attributionURL'):
xmp.set_property(
XMP_NS_CC,
'attributionURL',
work_properties['work_landing_page']
)
- if 'identifier' in work_properties:
xmp.register_namespace(XMP_NS_XMP, 'xmp')
+ if 'identifier' in work_properties:
+ if not xmp.does_property_exist(XMP_NS_XMP, 'Identifier'):
xmp.set_property(
XMP_NS_XMP,
'Identifier',
@@ -62,7 +65,9 @@ def embed_xmp_bytes(image: io.BytesIO, work_properties):
)
# Set generic XMP rights.
xmp.register_namespace(XMP_NS_XMP_Rights, 'xmpRights')
+ if not xmp.does_property_exist(XMP_NS_XMP_Rights, 'XMP_NS_XMP_Rights'):
xmp.set_property_bool(XMP_NS_XMP_Rights, 'Marked', True)
+ if not xmp.does_property_exist(XMP_NS_XMP_Rights, 'UsageTerms'):
usage = work_properties['attribution']
xmp.set_property(XMP_NS_XMP_Rights, 'UsageTerms', usage)
xmpfile.put_xmp(xmp)
