Skip to content

Commit

Permalink
Merge pull request #392 from whyboris/duration-undefined-fix
Browse files Browse the repository at this point in the history
fix cannot read property duration of undefined
  • Loading branch information
whyboris authored Mar 25, 2020
2 parents 71222d2 + 57a2c3e commit dd39de8
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions main-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,13 @@ function getBestStream(metadata) {
* Return the duration from file by parsing metadata
* @param metadata
*/
function getFileDuration(metadata) {
try {
function getFileDuration(metadata): number {
if (metadata && metadata.streams && metadata.streams[0] && metadata.streams[0].duration ) {
return metadata.streams[0].duration;
} catch (e1) {
try {
return metadata.format.duration;
} catch (e2) {
return 0;
}
} else if (metadata && metadata.format && metadata.format.duration ) {
return metadata.format.duration;
} else {
return 0;
}
}

Expand All @@ -474,7 +472,7 @@ function extractMetadataForThisONEFile(
} else {
const metadata = JSON.parse(data);
const stream = getBestStream(metadata);
const fileDuration = getFileDuration(metadata);
const fileDuration: number = getFileDuration(metadata);

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

0 comments on commit dd39de8

Please sign in to comment.