diff --git a/src/backend/model/fileaccess/MetadataLoader.ts b/src/backend/model/fileaccess/MetadataLoader.ts index fd7364de..d597b6d4 100644 --- a/src/backend/model/fileaccess/MetadataLoader.ts +++ b/src/backend/model/fileaccess/MetadataLoader.ts @@ -666,6 +666,22 @@ export class MetadataLoader { metadata.creationDate; } } + if ((sidecarData as SideCar).exif !== undefined) { + if ( + (sidecarData as SideCar).exif.GPSLatitude !== undefined && + (sidecarData as SideCar).exif.GPSLongitude !== undefined + ) { + metadata.positionData = metadata.positionData || {}; + metadata.positionData.GPSData = {}; + + metadata.positionData.GPSData.longitude = Utils.xmpExifGpsCoordinateToDecimalDegrees( + (sidecarData as SideCar).exif.GPSLongitude + ); + metadata.positionData.GPSData.latitude = Utils.xmpExifGpsCoordinateToDecimalDegrees( + (sidecarData as SideCar).exif.GPSLatitude + ); + } + } } } } diff --git a/src/common/Utils.ts b/src/common/Utils.ts index f707c883..710a43f8 100644 --- a/src/common/Utils.ts +++ b/src/common/Utils.ts @@ -381,6 +381,14 @@ export class Utils { } return ret; } + + public static xmpExifGpsCoordinateToDecimalDegrees(text: string): number { + const parts = text.match(/^([0-9]+),([0-9.]+)([EWNS])$/); + const degrees: number = parseInt(parts[1], 10); + const minutes: number = parseFloat(parts[2]); + const sign = (parts[3] === "N" || parts[3] === "E") ? 1 : -1; + return sign * (degrees + (minutes / 60.0)) + } } export class LRU { diff --git a/src/common/entities/MediaDTO.ts b/src/common/entities/MediaDTO.ts index 84db8157..05acc4ce 100644 --- a/src/common/entities/MediaDTO.ts +++ b/src/common/entities/MediaDTO.ts @@ -30,11 +30,17 @@ export interface MediaDimension { } export interface SideCar { + exif?: SideCarExif; dc?: SideCarDc; xmp?: SideCarXmp; photoshop?: SideCarPhotoshop; } +export interface SideCarExif { + GPSLatitude?: string; + GPSLongitude?: string; +} + export interface SideCarDc { subject?: string[]; } diff --git a/test/backend/assets/sidecar/20240107_110258.json b/test/backend/assets/sidecar/20240107_110258.json index 6052ac14..a466e4f9 100644 --- a/test/backend/assets/sidecar/20240107_110258.json +++ b/test/backend/assets/sidecar/20240107_110258.json @@ -18,5 +18,11 @@ "Výlet", "Travel" ], + "positionData": { + "GPSData": { + "latitude": 50.08958748333333, + "longitude": 14.397409516666666 + } + }, "rating": 3 } diff --git a/test/backend/assets/sidecar/20240121_102400.json b/test/backend/assets/sidecar/20240121_102400.json index b3579d2b..551b7d9a 100644 --- a/test/backend/assets/sidecar/20240121_102400.json +++ b/test/backend/assets/sidecar/20240121_102400.json @@ -19,5 +19,11 @@ "Výlet", "Travel" ], + "positionData": { + "GPSData": { + "latitude": 50.08958748333333, + "longitude": 14.397409516666666 + } + }, "rating": 3 } diff --git a/test/backend/assets/sidecar/20240128_185808.json b/test/backend/assets/sidecar/20240128_185808.json index 7afeb9d9..9d53fca1 100644 --- a/test/backend/assets/sidecar/20240128_185808.json +++ b/test/backend/assets/sidecar/20240128_185808.json @@ -19,5 +19,11 @@ "Výlet", "Travel" ], + "positionData": { + "GPSData": { + "latitude": 50.08958748333333, + "longitude": 14.397409516666666 + } + }, "rating": 3 }