Skip to content

Commit dd39de8

Browse files
authored
Merge pull request #392 from whyboris/duration-undefined-fix
fix cannot read property duration of undefined
2 parents 71222d2 + 57a2c3e commit dd39de8

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

main-support.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -441,15 +441,13 @@ function getBestStream(metadata) {
441441
* Return the duration from file by parsing metadata
442442
* @param metadata
443443
*/
444-
function getFileDuration(metadata) {
445-
try {
444+
function getFileDuration(metadata): number {
445+
if (metadata && metadata.streams && metadata.streams[0] && metadata.streams[0].duration ) {
446446
return metadata.streams[0].duration;
447-
} catch (e1) {
448-
try {
449-
return metadata.format.duration;
450-
} catch (e2) {
451-
return 0;
452-
}
447+
} else if (metadata && metadata.format && metadata.format.duration ) {
448+
return metadata.format.duration;
449+
} else {
450+
return 0;
453451
}
454452
}
455453

@@ -474,7 +472,7 @@ function extractMetadataForThisONEFile(
474472
} else {
475473
const metadata = JSON.parse(data);
476474
const stream = getBestStream(metadata);
477-
const fileDuration = getFileDuration(metadata);
475+
const fileDuration: number = getFileDuration(metadata);
478476

479477
const duration = Math.round(fileDuration) || 0;
480478
const origWidth = stream.width || 0; // ffprobe does not detect it on some MKV streams

0 commit comments

Comments
 (0)