pythonxmppyexiv2

Writing modified subject data to XMP file fails (using pyexiv2)


My photo editor screwed up the tags for many of my photos. I took this as the final push to start getting familiar with Python and write a script to clean the tags. I found out that pyexiv2 might come in quite handy and I tried to basically follow the tutorial (http://tilloy.net/dev/pyexiv2/tutorial.html).

What I am trying to do:

Things look quite nice until I check the XMP file in an editor. The changed value just doesn't show up. However the XMP file gets a new timestamp and if I make the XMP file read-only, I get an error message. So it seems that something gets written to file. Just not the correct data.

Here is a minimal script that shows my problem:

import pyexiv2

key= 'Xmp.dc.subject'
metadata = pyexiv2.ImageMetadata('test.xmp')
metadata.read()

print metadata[key]
metadata[key] = ['NewTag']
print metadata[key]
metadata.write()

Its output is:

<Xmp.dc.subject [bag Text] = ['OldTag']>
<Xmp.dc.subject [bag Text] = ['NewTag']>
Script terminated.

But the relevant section of the XMP file still looks like this:

<dc:subject>
  <rdf:Bag>
    <rdf:li>OldTag</rdf:li>
  </rdf:Bag>
</dc:subject>

So what do I have to do in order to write the changed metadata to the XMP file?

Please note that I am a complete beginner to Python (but not to programming), so the issue might result from something trivial that I am not aware of. I am running Python 2.7.6 on Debian Linux.


Solution

  • The API documentation about pyexiv2.metadata.ImageMetadata says:

    A container for all the metadata embedded in an image.

    It provides convenient methods for the manipulation of EXIF, IPTC and XMP metadata embedded in image files such as JPEG and TIFF files, using Python types. It also provides access to the previews embedded in an image.

    It looks like sidecar files may not be supported for writing.