Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Build up

Manav Rathi0730ba72a6f2
diff --git a/web/packages/new/photos/services/exif.ts b/web/packages/new/photos/services/exif.ts
index cb55b0e786..8788b5d653 100644
--- a/web/packages/new/photos/services/exif.ts
+++ b/web/packages/new/photos/services/exif.ts
@@ -27,6 +27,14 @@ import type { EnteFile } from "../types/file";
// eslint-disable-next-line @typescript-eslint/no-empty-function
export const extractExif = () => {};
+/**
+ * Parse all date related fields from the metadata embedded in the file.
+ */
+const parseDates = (tags: ExifReader.ExpandedTags) => ({
+ ...parseExifDates(tags),
+ ...parseXMPDates(tags),
+});
+
/**
* Parse a date from an Exif date and offset tag combination.
*
@@ -128,6 +136,34 @@ const parseExifDate = (
);
};
+/**
+ * Parse date related tags from XMP.
+ *
+ * XMP might have tags with the same name (or an alias) of an Exif tag:
+ *
+ * - DateTimeOriginal
+ * - DateTimeDigitized (aka "CreateDate")
+ * - DateTime (aka "ModifyDate")
+ *
+ * In addition, it might have the following XMP specific tag:
+ *
+ * - MetadataDate
+ *
+ * In addition, it might have the following Photoshop tag:
+ *
+ * - DateCreated
+ *
+ * For a list of XMP tags, see https://exiftool.org/TagNames/XMP.html.
+ */
+const parseXMPDates = ({ xmp }: ExifReader.ExpandedTags) => ({
+ DateTimeOriginal: parseXMPDate(xmp?.DateTimeOriginal),
+ DateTimeDigitized:
+ parseXMPDate(xmp?.DateTimeDigitized) ?? parseXMPDate(xmp?.CreateDate),
+ DateTime: parseXMPDate(xmp?.DateTime) ?? parseXMPDate(xmp?.ModifyDate),
+ MetadataDate: parseXMPDate(xmp?.MetadataDate),
+ DateCreated: parseXMPDate(xmp?.DateCreated),
+});
+
/**
* Parse an XMP date tag.
*
@@ -136,10 +172,11 @@ const parseExifDate = (
*
* YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM]
*
- * See: https://exiftool.org/TagNames/XMP.html
*/
-const parseXMPDate = (s: string | undefined) => {
- if (!s) return undefined;
+const parseXMPDate = (xmpTag: ExifReader.XmpTag | undefined) => {
+ if (!xmpTag) return undefined;
+ const s = xmpTag.value;
+ if (typeof s != "string") return undefined;
// Do some minimal string manipulation to transform the XMP date string
// format into the Javascript date time string format. This is not going to