From 5dc1d628633694ef8b8e9fe786148eac69ff3235 Mon Sep 17 00:00:00 2001 From: gras Date: Tue, 16 Apr 2024 23:23:30 +0200 Subject: [PATCH] ready to read the data in order --- .../model/fileaccess/MetadataCreationDate.ts | 36 +++++++++---------- .../model/fileaccess/MetadataLoader.ts | 26 ++++++-------- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/backend/model/fileaccess/MetadataCreationDate.ts b/src/backend/model/fileaccess/MetadataCreationDate.ts index b7caae84..8c84a112 100644 --- a/src/backend/model/fileaccess/MetadataCreationDate.ts +++ b/src/backend/model/fileaccess/MetadataCreationDate.ts @@ -1,25 +1,25 @@ -//The elements are [tagname1, tag-name1] +//The elements are [tag-name1, tag-name2, type of tag-name2] //tagname1 is typically a full date time, but in some cases tagname1 and tagname2 together make up a full timestamp //Interesting exiftool forums posts about some of these tags: //exif.DateTimeOriginal, exif.CreateDate/exif.DateTimeDigitized and exif.ModifyDate: https://exiftool.org/forum/index.php?topic=13170.msg71174#msg71174 //https://exiftool.org/forum/index.php?topic=15555.msg83536#msg83536 -const DateTags: [string, string][] = [ - // Date tag Offset or time tag //Description - ["exif.DateTimeOriginal", "exif.OffsetTimeOriginal"], //Date and time when the original image was taken - shutter close time - ["exif.CreateDate", "exif.OffsetTimeDigitized"], //Date and time when the image was created - ["exif.DateTimeDigitized", "exif.OffsetTimeDigitized"], //Same as exif.CreateDate but older and newer spec name - ["ifd0.ModifyDate", ""], //The date and time of image creation. In Exif standard, it is the date and time the file was changed. - ["ihdr.Creation Time", ""], //Time of original image creation for PNG files - ["photoshop.DateCreated", ""], //The date the intellectual content of the document was created. Used and set by LightRoom among others - ["xmp:CreateDate", ""], //Date and time when the image was created (XMP standard) - ["iptc.DateCreated", "iptc.TimeCreated"], //Designates the date and optionally the time the content of the image was created rather than the date of the creation of the digital representation - ["quicktime.CreationDate", ""], //Date and time when the QuickTime movie was created"], - ["quicktime.CreateDate", ""], //Date and time when the QuickTime movie was created in UTC"], - ["heic.ContentCreateDate", ""], //Date and time when the HEIC image content was created"], - ["heic.CreationDate", ""], //Date and time when the HEIC image was created"], - ["tiff.DateTime", ""], //Date and time of image creation. This property is stored in XMP as xmp:ModifyDate. - ["xmp:ModifyDate", "exif.OffsetTime"], //Date and time when the image was last modified (XMP standard)"] - ["xmp.MetadataDate", ""], //The date and time that any metadata for this resource was last changed. It should be the same as or more recent than xmp:ModifyDate. +export const DateTags: [string, string, string][] = [ + // Date tag Offset or time tag Type //Description + ["exif.DateTimeOriginal", "exif.OffsetTimeOriginal", 'O'], //Date and time when the original image was taken - shutter close time + ["exif.CreateDate", "exif.OffsetTimeDigitized", 'O'], //Date and time when the image was created + ["exif.DateTimeDigitized", "exif.OffsetTimeDigitized", 'O'], //Same as exif.CreateDate but older and newer spec name + ["ifd0.ModifyDate", undefined, undefined], //The date and time of image creation. In Exif standard, it is the date and time the file was changed. + ["ihdr.Creation Time", undefined, undefined], //Time of original image creation for PNG files + ["photoshop.DateCreated", undefined, undefined], //The date the intellectual content of the document was created. Used and set by LightRoom among others + ["xmp:CreateDate", undefined, undefined], //Date and time when the image was created (XMP standard) + ["iptc.DateCreated", "iptc.TimeCreated", 'T'], //Designates the date and optionally the time the content of the image was created rather than the date of the creation of the digital representation + ["quicktime.CreationDate", undefined, undefined], //Date and time when the QuickTime movie was created"], + ["quicktime.CreateDate", undefined, undefined], //Date and time when the QuickTime movie was created in UTC"], + ["heic.ContentCreateDate", undefined, undefined], //Date and time when the HEIC image content was created"], + ["heic.CreationDate", undefined, undefined], //Date and time when the HEIC image was created"], + ["tiff.DateTime", undefined, undefined], //Date and time of image creation. This property is stored in XMP as xmp:ModifyDate. + ["xmp:ModifyDate", "exif.OffsetTime", 'O'], //Date and time when the image was last modified (XMP standard)"] + ["xmp.MetadataDate", undefined, undefined], //The date and time that any metadata for this resource was last changed. It should be the same as or more recent than xmp:ModifyDate. ]; diff --git a/src/backend/model/fileaccess/MetadataLoader.ts b/src/backend/model/fileaccess/MetadataLoader.ts index 6b54175d..003b73b7 100644 --- a/src/backend/model/fileaccess/MetadataLoader.ts +++ b/src/backend/model/fileaccess/MetadataLoader.ts @@ -285,6 +285,7 @@ export class MetadataLoader { MetadataLoader.mapKeywords(metadata, exif); MetadataLoader.mapTitle(metadata, exif); MetadataLoader.mapCaption(metadata, exif); + MetadataLoader.mapTimestampAndOffset2(metadata, exif); MetadataLoader.mapTimestampAndOffset(metadata, exif); MetadataLoader.mapCameraData(metadata, exif); MetadataLoader.mapGPS(metadata, exif); @@ -361,28 +362,23 @@ export class MetadataLoader { metadata.caption = exif.dc?.description?.value || Utils.asciiToUTF8(exif.iptc?.Caption) || metadata.caption || exif.ifd0?.ImageDescription || exif.exif?.UserComment?.value || exif.Iptc4xmpCore?.ExtDescrAccessibility?.value ||exif.acdsee?.notes; } - private static mapTimestampAndOffset2(metadata: PhotoMetadata, exif: any) { - function getValueFromPath(company: Company, path: string): any { - // Avoid using eval() due to security risks - return eval(`company.${path}`); - } - function getValueFromPath(company: Company, path: string): any { + private static getValue(exif: any, path: string): any { const pathElements = path.split('.'); - let currentObject: any = company; - - for (const element of pathElements) { - const tmp = currentObject[element]; + let currentObject: any = exif; + for (const pathElm of pathElements) { + const tmp = currentObject[pathElm]; if (tmp === undefined) { - // Handle case where path is invalid return undefined; } currentObject = tmp; } - return currentObject; -} - for (const [main, extra] of DateTags) { - const pathelms[] = main.split["."]; + } + + private static mapTimestampAndOffset2(metadata: PhotoMetadata, exif: any) { + let ts; + for (const [mainpath, extrapath, extratype] of DateTags) { + ts = MetadataLoader.getValue(exif, mainpath); }