1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08: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 {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;