1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00

Reading camera metadata from multiple sources

This commit is contained in:
gras 2024-04-01 00:09:53 +02:00
parent 893df7db74
commit d628c816da
4 changed files with 19 additions and 20 deletions

View File

@ -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;
}

View File

@ -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];
}
}

View File

@ -29,5 +29,9 @@
"keywords": [
"Thing3"
],
"title": "The title"
"title": "The title",
"cameraData": {
"make": "Cam Make",
"model": "Cam Model"
}
}

View File

@ -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"
}
}