From d89c0eea8c73a9c5460c27dfa4555e84e6e525a9 Mon Sep 17 00:00:00 2001 From: kylon Date: Thu, 16 Apr 2020 18:21:02 +0200 Subject: [PATCH 1/3] Fix progress bar, remove temp file on ffmpeg error (#66) * Delete the video file on ffmpeg error * rework chunk calculation (with more tests it turns out it was not good for all durations) Co-authored-by: kylon --- src/Metadata.ts | 2 +- src/Utils.ts | 2 +- src/destreamer.ts | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Metadata.ts b/src/Metadata.ts index 1288177..a0e9d97 100644 --- a/src/Metadata.ts +++ b/src/Metadata.ts @@ -17,7 +17,7 @@ function durationToTotalChunks(duration: string) { const mins = durationObj['minutes'] ?? 0; const secs = Math.ceil(durationObj['seconds'] ?? 0); - return hrs * 1000 + mins * 100 + secs; + return (hrs * 60) + mins + (secs / 60); } diff --git a/src/Utils.ts b/src/Utils.ts index 2e915cc..3d8c244 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -137,5 +137,5 @@ export function ffmpegTimemarkToChunk(timemark: string) { const mins = parseInt(timeVals[1]); const secs = parseInt(timeVals[2]); - return hrs * 1000 + mins * 100 + secs; + return (hrs * 60) + mins + (secs / 60); } diff --git a/src/destreamer.ts b/src/destreamer.ts index 9b7d9c7..a56a024 100644 --- a/src/destreamer.ts +++ b/src/destreamer.ts @@ -15,6 +15,7 @@ import isElevated from 'is-elevated'; import puppeteer from 'puppeteer'; import colors from 'colors'; import path from 'path'; +import fs from 'fs'; import sanitize from 'sanitize-filename'; import cliProgress from 'cli-progress'; @@ -148,7 +149,6 @@ async function downloadVideo(videoUrls: string[], outputDirectories: string[], s const outDirsIdxInc = outputDirectories.length > 1 ? 1:0; for (let i=0, j=0, l=metadata.length; i { const currentChunks = ffmpegTimemarkToChunk(data.out_time); - const incChunk = currentChunks - previousChunks; - pbar.increment(incChunk, { + pbar.update(currentChunks, { speed: data.bitrate }); - - previousChunks = currentChunks; }); ffmpegCmd.on('error', (error: any) => { pbar.stop(); + fs.unlinkSync(outputPath); console.log(`\nffmpeg returned an error: ${error.message}`); process.exit(ERROR_CODE.UNK_FFMPEG_ERROR); }); From 3b48221d27143cbbee917ee5a5812cc03cd9aabc Mon Sep 17 00:00:00 2001 From: kylon Date: Thu, 16 Apr 2020 18:36:36 +0200 Subject: [PATCH 2/3] Delete video file on SIGINT too and silence ENOENT error (#67) Co-authored-by: kylon --- src/destreamer.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/destreamer.ts b/src/destreamer.ts index a56a024..3c7e276 100644 --- a/src/destreamer.ts +++ b/src/destreamer.ts @@ -194,13 +194,21 @@ async function downloadVideo(videoUrls: string[], outputDirectories: string[], s ffmpegCmd.on('error', (error: any) => { pbar.stop(); - fs.unlinkSync(outputPath); + + try { + fs.unlinkSync(outputPath); + } catch (e) {} + console.log(`\nffmpeg returned an error: ${error.message}`); process.exit(ERROR_CODE.UNK_FFMPEG_ERROR); }); process.on('SIGINT', () => { pbar.stop(); + + try { + fs.unlinkSync(outputPath); + } catch (e) {} }); // let the magic begin... From e35ab6a9df9e3a82ffe7c81776e93a0d32890c59 Mon Sep 17 00:00:00 2001 From: Adrian Calinescu Date: Thu, 16 Apr 2020 19:45:49 +0300 Subject: [PATCH 3/3] Adding temporary bootstrapers until we move to single binary releases (#63) --- destreamer.cmd | 1 + destreamer.ps1 | 1 + destreamer.sh | 1 + 3 files changed, 3 insertions(+) create mode 100644 destreamer.cmd create mode 100644 destreamer.ps1 create mode 100644 destreamer.sh diff --git a/destreamer.cmd b/destreamer.cmd new file mode 100644 index 0000000..2c922e2 --- /dev/null +++ b/destreamer.cmd @@ -0,0 +1 @@ +node.exe build\src\destreamer.js %* \ No newline at end of file diff --git a/destreamer.ps1 b/destreamer.ps1 new file mode 100644 index 0000000..dba5b34 --- /dev/null +++ b/destreamer.ps1 @@ -0,0 +1 @@ +node.exe build\src\destreamer.js $args \ No newline at end of file diff --git a/destreamer.sh b/destreamer.sh new file mode 100644 index 0000000..3d65b8c --- /dev/null +++ b/destreamer.sh @@ -0,0 +1 @@ +node build/src/destreamer.js "$@" \ No newline at end of file