Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xmp file date/time changes overwritten #1998

Closed
jim-easterbrook opened this issue Nov 15, 2021 · 4 comments
Closed

Xmp file date/time changes overwritten #1998

jim-easterbrook opened this issue Nov 15, 2021 · 4 comments
Labels

Comments

@jim-easterbrook
Copy link
Contributor

I'm revisiting a bug I raised 4 years ago https://dev.exiv2.org/issues/1313

I start with a simple XMP file with just one item of metadata:

<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.4.0-Exiv2">
 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:Description rdf:about=""
    xmlns:xmp="http://ns.adobe.com/xap/1.0/"
   xmp:CreateDate="2021-02-03T12:34:56+02:00"/>
 </rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>

Reading this file with libexiv2 reports the following data:

Exif.Photo.DateTimeDigitized: 2021:02:03 10:34:56
Iptc.Application2.DigitizationDate: 2021-02-03
Iptc.Envelope.CharacterSet: 
Xmp.xmp.CreateDate: 2021-02-03T12:34:56+02:00

The Exif and Iptc values are synthesised in XmpSidecar::readMetadata() lines 110-111. (This is not the place to discuss if synthesising values is a good idea.) Note that Iptc.Application2.DigitizationTime is not synthesised.

If I change the Xmp time:

xmpData['Xmp.xmp.CreateDate'] = '2021-02-03T11:00:00+01:00'

it gets changed back to its original value by XmpSidecar::writeMetadata(). However, if I change the date as well as the time:

xmpData['Xmp.xmp.CreateDate'] = '2021-02-02T11:00:00+01:00'

then the new value is not modified by XmpSidecar::writeMetadata(). Looking at xmpsidecar.cpp I see line 160 detects a new date/time value by comparing the first 10 characters of the string, i.e. the date but not the time!

I don't really understand the intent behind all this. Lines 144-145 appear to copy exif and iptc data to xmp, regardless of what might already be in xmp. Lines 147-150 appear to try and put back the xmp values that have just been over-written, then lines 152-164 appear to try and restore date/time stamps. Would this even be needed if the iptc time values had been synthesised as they have time zone info anyway.

@jim-easterbrook
Copy link
Contributor Author

Aha! Moving lines 147-150 to be after lines 152-164 solves my problem and all the unit tests still pass. I'll submit a PR.

@clanmills
Copy link
Collaborator

Well done, Jim. I don't know the rationale for the convertors. This kind of manipulation should be carried out by applications and should not be in the metadata engine.

@jim-easterbrook
Copy link
Contributor Author

I agree, but I'm happy to live with it now I know it's there. (Using clearExifData() and clearIptcData() immediately after opening an xmp file does the job.)

I think my changes honour the intent of the authors of those bits of xmpsidecar.cpp as it makes the "restore dates if they lost their TZ info" step part of the copying back of Exif & Iptc, all of which are selectively undone by the final "restore tags which were modified by the convertors" step.

@jim-easterbrook
Copy link
Contributor Author

I've submitted a test file now that I've understood the test system a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants