From d628c816da3481337da725c7351eff4ac56ad98c Mon Sep 17 00:00:00 2001 From: gras Date: Mon, 1 Apr 2024 00:09:53 +0200 Subject: [PATCH] Reading camera metadata from multiple sources --- .../model/fileaccess/MetadataLoader.ts | 25 ++++++------------- src/common/Utils.ts | 2 +- test/backend/assets/sidecar/flatxmp.json | 6 ++++- test/backend/assets/sidecar/headline.json | 6 ++++- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/backend/model/fileaccess/MetadataLoader.ts b/src/backend/model/fileaccess/MetadataLoader.ts index 8feb8427..478fc212 100644 --- a/src/backend/model/fileaccess/MetadataLoader.ts +++ b/src/backend/model/fileaccess/MetadataLoader.ts @@ -429,18 +429,13 @@ export class MetadataLoader { private static mapCameraData(metadata: PhotoMetadata, exif: any) { metadata.cameraData = metadata.cameraData || {}; - if (exif.ifd0) { - if (exif.ifd0.Make && exif.ifd0.Make !== '') { - metadata.cameraData.make = '' + exif.ifd0.Make; - } - if (exif.ifd0.Model && exif.ifd0.Model !== '') { - metadata.cameraData.model = '' + exif.ifd0.Model; - } - } + metadata.cameraData.make = exif.ifd0?.Make || exif.tiff?.Make || metadata.cameraData.make; + + metadata.cameraData.model = exif.ifd0?.Model || exif.tiff?.Model || metadata.cameraData.model; + + metadata.cameraData.lens = exif.exif?.LensModel || exif.exifEX?.LensModel || metadata.cameraData.lens; + if (exif.exif) { - if (exif.exif.LensModel && exif.exif.LensModel !== '') { - metadata.cameraData.lens = '' + exif.exif.LensModel; - } if (Utils.isUInt32(exif.exif.ISO)) { metadata.cameraData.ISO = parseInt('' + exif.exif.ISO, 10); } @@ -460,6 +455,7 @@ export class MetadataLoader { ); } } + Utils.removeNullOrEmptyObj(metadata.cameraData); if (Object.keys(metadata.cameraData).length === 0) { delete metadata.cameraData; } @@ -484,13 +480,8 @@ export class MetadataLoader { } catch (err) { Logger.error(LOG_TAG, 'Error during reading of GPS data: ' + err); } finally { - if (metadata.positionData?.GPSData && - (Object.keys(metadata.positionData.GPSData).length === 0 || - metadata.positionData.GPSData.longitude === undefined || - metadata.positionData.GPSData.latitude === undefined)) { - delete metadata.positionData.GPSData; - } if (metadata.positionData) { + Utils.removeNullOrEmptyObj(metadata.positionData); if (Object.keys(metadata.positionData).length === 0) { delete metadata.positionData; } diff --git a/src/common/Utils.ts b/src/common/Utils.ts index 4cafa1ad..f6d768a8 100644 --- a/src/common/Utils.ts +++ b/src/common/Utils.ts @@ -35,7 +35,7 @@ export class Utils { delete obj[key]; } } - } else if (obj[key] === null) { + } else if (obj[key] === null || obj[key] === undefined) { delete obj[key]; } } diff --git a/test/backend/assets/sidecar/flatxmp.json b/test/backend/assets/sidecar/flatxmp.json index 008108db..10dfa9d9 100644 --- a/test/backend/assets/sidecar/flatxmp.json +++ b/test/backend/assets/sidecar/flatxmp.json @@ -29,5 +29,9 @@ "keywords": [ "Thing3" ], - "title": "The title" + "title": "The title", + "cameraData": { + "make": "Cam Make", + "model": "Cam Model" + } } \ No newline at end of file diff --git a/test/backend/assets/sidecar/headline.json b/test/backend/assets/sidecar/headline.json index 7d6cb058..0a1c60cf 100644 --- a/test/backend/assets/sidecar/headline.json +++ b/test/backend/assets/sidecar/headline.json @@ -8,5 +8,9 @@ "fileSize": 1430, "keywords": ["Person 1", "Person 2"], "caption": "XMP description", - "title": "Photoshop Headline" + "title": "Photoshop Headline", + "cameraData": { + "make": "CamMake", + "model": "CamModel" + } } \ No newline at end of file