reducing metadata loading error severity
This commit is contained in:
parent
293195977a
commit
5263c77b40
@ -8,6 +8,7 @@ import {Config} from '../../../common/config/private/Config';
|
||||
import {VideoDTO} from '../../../common/entities/VideoDTO';
|
||||
import {FileDTO} from '../../../common/entities/FileDTO';
|
||||
import {MetadataLoader} from './MetadataLoader';
|
||||
import {Logger} from '../../Logger';
|
||||
|
||||
const LOG_TAG = '[DiskManagerTask]';
|
||||
|
||||
@ -32,21 +33,6 @@ export class DiskMangerWorker {
|
||||
]
|
||||
};
|
||||
|
||||
private static isImage(fullPath: string) {
|
||||
const extension = path.extname(fullPath).toLowerCase();
|
||||
return this.SupportedEXT.photo.indexOf(extension) !== -1;
|
||||
}
|
||||
|
||||
private static isVideo(fullPath: string) {
|
||||
const extension = path.extname(fullPath).toLowerCase();
|
||||
return this.SupportedEXT.video.indexOf(extension) !== -1;
|
||||
}
|
||||
|
||||
private static isMetaFile(fullPath: string) {
|
||||
const extension = path.extname(fullPath).toLowerCase();
|
||||
return this.SupportedEXT.metaFile.indexOf(extension) !== -1;
|
||||
}
|
||||
|
||||
public static calcLastModified(stat: Stats) {
|
||||
return Math.max(stat.ctime.getTime(), stat.mtime.getTime());
|
||||
}
|
||||
@ -106,11 +92,15 @@ export class DiskMangerWorker {
|
||||
}
|
||||
} else if (photosOnly === false && Config.Client.Video.enabled === true &&
|
||||
DiskMangerWorker.isVideo(fullFilePath)) {
|
||||
directory.media.push(<VideoDTO>{
|
||||
name: file,
|
||||
directory: null,
|
||||
metadata: await MetadataLoader.loadVideoMetadata(fullFilePath)
|
||||
});
|
||||
try {
|
||||
directory.media.push(<VideoDTO>{
|
||||
name: file,
|
||||
directory: null,
|
||||
metadata: await MetadataLoader.loadVideoMetadata(fullFilePath)
|
||||
});
|
||||
} catch (e) {
|
||||
Logger.warn('Media loading error, skipping: ' + file);
|
||||
}
|
||||
|
||||
} else if (photosOnly === false && Config.Client.MetaFile.enabled === true &&
|
||||
DiskMangerWorker.isMetaFile(fullFilePath)) {
|
||||
@ -134,4 +124,19 @@ export class DiskMangerWorker {
|
||||
|
||||
}
|
||||
|
||||
private static isImage(fullPath: string) {
|
||||
const extension = path.extname(fullPath).toLowerCase();
|
||||
return this.SupportedEXT.photo.indexOf(extension) !== -1;
|
||||
}
|
||||
|
||||
private static isVideo(fullPath: string) {
|
||||
const extension = path.extname(fullPath).toLowerCase();
|
||||
return this.SupportedEXT.video.indexOf(extension) !== -1;
|
||||
}
|
||||
|
||||
private static isMetaFile(fullPath: string) {
|
||||
const extension = path.extname(fullPath).toLowerCase();
|
||||
return this.SupportedEXT.metaFile.indexOf(extension) !== -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -35,38 +35,39 @@ export class MetadataLoader {
|
||||
metadata.fileSize = stat.size;
|
||||
} catch (err) {
|
||||
}
|
||||
ffmpeg(fullPath).ffprobe((err: any, data: FfprobeData) => {
|
||||
if (!!err || data === null) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
if (!data.streams[0]) {
|
||||
return resolve(metadata);
|
||||
}
|
||||
|
||||
try {
|
||||
for (let i = 0; i < data.streams.length; i++) {
|
||||
if (data.streams[i].width) {
|
||||
metadata.size.width = data.streams[i].width;
|
||||
metadata.size.height = data.streams[i].height;
|
||||
|
||||
if (Utils.isInt32(Math.floor(data.streams[i].duration * 1000))) {
|
||||
metadata.duration = Math.floor(data.streams[i].duration * 1000);
|
||||
}
|
||||
|
||||
if (Utils.isInt32(parseInt(data.streams[i].bit_rate, 10))) {
|
||||
metadata.duration = parseInt(data.streams[i].bit_rate, 10) || null;
|
||||
}
|
||||
metadata.creationDate = Date.parse(data.streams[i].tags.creation_time);
|
||||
break;
|
||||
}
|
||||
try {
|
||||
ffmpeg(fullPath).ffprobe((err: any, data: FfprobeData) => {
|
||||
if (!!err || data === null || !data.streams[0]) {
|
||||
return resolve(metadata);
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
}
|
||||
|
||||
try {
|
||||
for (let i = 0; i < data.streams.length; i++) {
|
||||
if (data.streams[i].width) {
|
||||
metadata.size.width = data.streams[i].width;
|
||||
metadata.size.height = data.streams[i].height;
|
||||
|
||||
if (Utils.isInt32(Math.floor(data.streams[i].duration * 1000))) {
|
||||
metadata.duration = Math.floor(data.streams[i].duration * 1000);
|
||||
}
|
||||
|
||||
if (Utils.isInt32(parseInt(data.streams[i].bit_rate, 10))) {
|
||||
metadata.duration = parseInt(data.streams[i].bit_rate, 10) || null;
|
||||
}
|
||||
metadata.creationDate = Date.parse(data.streams[i].tags.creation_time);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
}
|
||||
|
||||
return resolve(metadata);
|
||||
});
|
||||
} catch (e) {
|
||||
return resolve(metadata);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user