From 03e0822181e0735742d0f482e7a9ed1600b21b1f Mon Sep 17 00:00:00 2001 From: Martin Kampas Date: Fri, 1 Mar 2024 13:20:09 +0100 Subject: [PATCH] Improve on reading dates from XMP sidecars --- .../model/fileaccess/MetadataLoader.ts | 43 ++++++++++++++++++- src/common/entities/MediaDTO.ts | 8 ++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/backend/model/fileaccess/MetadataLoader.ts b/src/backend/model/fileaccess/MetadataLoader.ts index 7225ce6d..9aa0b34f 100644 --- a/src/backend/model/fileaccess/MetadataLoader.ts +++ b/src/backend/model/fileaccess/MetadataLoader.ts @@ -160,10 +160,31 @@ export class MetadataLoader { } } } + let hasPhotoshopDate = false; + if ((sidecarData as SideCar).photoshop !== undefined) { + if ((sidecarData as SideCar).photoshop.DateCreated !== undefined) { + const date = Utils.timestampToMS((sidecarData as SideCar).photoshop.DateCreated, null); + if (date) { + metadata.creationDate = date; + hasPhotoshopDate = true; + } + } + } if ((sidecarData as SideCar).xmp !== undefined) { if ((sidecarData as SideCar).xmp.Rating !== undefined) { metadata.rating = (sidecarData as SideCar).xmp.Rating; } + if ( + !hasPhotoshopDate && ( + (sidecarData as SideCar).xmp.CreateDate !== undefined || + (sidecarData as SideCar).xmp.ModifyDate !== undefined + ) + ) { + metadata.creationDate = + Utils.timestampToMS((sidecarData as SideCar).xmp.CreateDate, null) || + Utils.timestampToMS((sidecarData as SideCar).xmp.ModifyDate, null) || + metadata.creationDate; + } } } } @@ -611,12 +632,30 @@ export class MetadataLoader { } } } + let hasPhotoshopDate = false; + if ((sidecarData as SideCar).photoshop !== undefined) { + if ((sidecarData as SideCar).photoshop.DateCreated !== undefined) { + const date = Utils.timestampToMS((sidecarData as SideCar).photoshop.DateCreated, null); + if (date) { + metadata.creationDate = date; + hasPhotoshopDate = true; + } + } + } if ((sidecarData as SideCar).xmp !== undefined) { if ((sidecarData as SideCar).xmp.Rating !== undefined) { metadata.rating = (sidecarData as SideCar).xmp.Rating; } - if ((sidecarData as SideCar).xmp.CreateDate) { - metadata.creationDate = Utils.timestampToMS((sidecarData as SideCar).xmp.CreateDate, null); + if ( + !hasPhotoshopDate && ( + (sidecarData as SideCar).xmp.CreateDate !== undefined || + (sidecarData as SideCar).xmp.ModifyDate !== undefined + ) + ) { + metadata.creationDate = + Utils.timestampToMS((sidecarData as SideCar).xmp.CreateDate, null) || + Utils.timestampToMS((sidecarData as SideCar).xmp.ModifyDate, null) || + metadata.creationDate; } } } diff --git a/src/common/entities/MediaDTO.ts b/src/common/entities/MediaDTO.ts index c1d9f8e9..84db8157 100644 --- a/src/common/entities/MediaDTO.ts +++ b/src/common/entities/MediaDTO.ts @@ -32,6 +32,7 @@ export interface MediaDimension { export interface SideCar { dc?: SideCarDc; xmp?: SideCarXmp; + photoshop?: SideCarPhotoshop; } export interface SideCarDc { @@ -41,6 +42,13 @@ export interface SideCarDc { export interface SideCarXmp { Rating?: RatingTypes; CreateDate?: string; + ModifyDate?: string; +} + +export interface SideCarPhotoshop { + // Corresponds to Exif.Photo.DateTimeOriginal. No corresponding key exists in + // the xmp namespace! + DateCreated?: string; } export const MediaDTOUtils = {