diff --git a/src/backend/model/fileaccess/MetadataLoader.ts b/src/backend/model/fileaccess/MetadataLoader.ts index 0e4915f7..8cd76d49 100644 --- a/src/backend/model/fileaccess/MetadataLoader.ts +++ b/src/backend/model/fileaccess/MetadataLoader.ts @@ -12,6 +12,8 @@ import {IptcParser} from 'ts-node-iptc'; import {FFmpegFactory} from '../FFmpegFactory'; import {FfprobeData} from 'fluent-ffmpeg'; import {Utils} from '../../../common/Utils'; +import * as exifr from 'exifr'; +import * as path from 'path'; const LOG_TAG = '[MetadataLoader]'; const ffmpeg = FFmpegFactory.get(); @@ -30,6 +32,29 @@ export class MetadataLoader { fileSize: 0, fps: 0, }; + + try { + // search for sidecar and merge metadata + const fullPathWithoutExt = path.parse(fullPath).name; + const sidecarPaths = [ + fullPath + '.xmp', + fullPath + '.XMP', + fullPathWithoutExt + '.xmp', + fullPathWithoutExt + '.XMP', + ]; + + for (const sidecarPath of sidecarPaths) { + if (fs.existsSync(sidecarPath)) { + const sidecarData = exifr.sidecar(sidecarPath); + sidecarData.then((response) => { + metadata.keywords = [(response as any).dc.subject].flat(); + }); + } + } + } catch (err) { + // ignoring errors + } + try { const stat = fs.statSync(fullPath); metadata.fileSize = stat.size;