drewnoakes / metadata-extractor

Extracts Exif, IPTC, XMP, ICC and other metadata from image, video and audio files
Apache License 2.0
2.55k stars 479 forks source link

Ability to extract XMP-photoshop:DateCreated #517

Closed cowwoc closed 3 years ago

cowwoc commented 3 years ago

This issue might be related to https://github.com/drewnoakes/metadata-extractor/issues/118

I want to extract photoshop:DateCreated from an image with the following metadata:

<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.6-c148 79.164036, 2019/08/13-01:06:57        ">
   <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
      <rdf:Description rdf:about=""
            xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/"
            xmlns:exif="http://ns.adobe.com/exif/1.0/"
            xmlns:xmp="http://ns.adobe.com/xap/1.0/"
            xmlns:dc="http://purl.org/dc/elements/1.1/">
         <photoshop:DateCreated>2016-01-28T12:21:20</photoshop:DateCreated>
         <photoshop:ColorMode>3</photoshop:ColorMode>
         <photoshop:ICCProfile>sRGB IEC61966-2.1</photoshop:ICCProfile>
         <exif:UserComment>
            <rdf:Alt>
               <rdf:li xml:lang="x-default">Screenshot</rdf:li>
            </rdf:Alt>
         </exif:UserComment>
         <xmp:CreateDate>2021-01-03T00:21:38-05:00</xmp:CreateDate>
         <xmp:ModifyDate>2020-05-04T12:40-04:00</xmp:ModifyDate>
         <xmp:MetadataDate>2020-05-04T12:40-04:00</xmp:MetadataDate>
         <dc:format>image/png</dc:format>
      </rdf:Description>
   </rdf:RDF>
</x:xmpmeta>

I have no idea what software/camera was used to generate this image. The image contains a photo of my child so I'm not really comfortable sharing it over Github. Hopefully the above metadata is enough for you to add support.

Also, for what it's worth exiftool parses this information into CreateDate. Per https://exiftool.org/forum/index.php?topic=8782.0 it sounds as if this is part of XMP-photoshop:DateCreated.

drewnoakes commented 3 years ago

This library doesn't interpret XMP data, it only extracts it. This is because the format of XMP doesn't fit with the directory/tag model used for all other kinds of metadata in the library. If you want to access XMP properties you can do so via the XmpDirectory.

drewnoakes commented 3 years ago

Closing for now. If I missed something, we can reopen.

cowwoc commented 3 years ago

I wasn't aware I could do this. Thank you!

For anyone else running across this issue, here is what worked for me:

XmpDirectory xmp = metadata.getFirstDirectoryOfType(XmpDirectory.class);
if (xmp != null)
{
    XMPDateTime property;
    try
    {
        property = xmp.getXMPMeta().
            getPropertyDate(Schema.EXIF_SPECIFIC_PROPERTIES, "DateTimeOriginal");
    }
    catch (XMPException e)
    {
        throw new IOException(e);
    }
    if (property != null)
        return property.getCalendar().getTime();
}