1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-23 01:27:14 +02:00

metadataloader.ts modifications to add xmp sidecar

Modified module imports and added code to read xmp sidecar for videometadata using exifr module.
This commit is contained in:
Graham Alderson 2023-11-14 15:30:17 +12:00
parent 54b16285dc
commit 2702f9d41d

View File

@ -12,6 +12,8 @@ import {IptcParser} from 'ts-node-iptc';
import {FFmpegFactory} from '../FFmpegFactory'; import {FFmpegFactory} from '../FFmpegFactory';
import {FfprobeData} from 'fluent-ffmpeg'; import {FfprobeData} from 'fluent-ffmpeg';
import {Utils} from '../../../common/Utils'; import {Utils} from '../../../common/Utils';
import * as exifr from 'exifr';
import * as path from 'path';
const LOG_TAG = '[MetadataLoader]'; const LOG_TAG = '[MetadataLoader]';
const ffmpeg = FFmpegFactory.get(); const ffmpeg = FFmpegFactory.get();
@ -30,6 +32,29 @@ export class MetadataLoader {
fileSize: 0, fileSize: 0,
fps: 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 { try {
const stat = fs.statSync(fullPath); const stat = fs.statSync(fullPath);
metadata.fileSize = stat.size; metadata.fileSize = stat.size;