From 67cb62ce3cfc9ee9fba34a218af76963a0311aa2 Mon Sep 17 00:00:00 2001 From: Don <10512545+aleksamagicka@users.noreply.github.com> Date: Sun, 26 Apr 2020 17:03:03 +0200 Subject: [PATCH] Add noCleanup argument (#95) * Added noCleanup argument (don't delete temp audio/video files on ffmpeg error) * Added argument to README Co-authored-by: Aleksa Savic --- README.md | 2 ++ src/CommandLineParser.ts | 7 +++++++ src/destreamer.ts | 9 ++++----- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 28c54f3..27b91a2 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,8 @@ Options: --verbose, -v Print additional information to the console (use this before opening an issue on GitHub) [boolean] [default: false] + --noCleanup, --nc Don't delete the downloaded video file when an FFmpeg + error occurs [boolean] [default: false] ``` Download a video - diff --git a/src/CommandLineParser.ts b/src/CommandLineParser.ts index 577c9b9..bf98e1f 100644 --- a/src/CommandLineParser.ts +++ b/src/CommandLineParser.ts @@ -54,6 +54,13 @@ export const argv = yargs.options({ type: 'boolean', default: false, demandOption: false + }, + noCleanup: { + alias: 'nc', + describe: `Don't delete the downloaded video file when an FFmpeg error occurs`, + type: 'boolean', + default: false, + demandOption: false } }) /** diff --git a/src/destreamer.ts b/src/destreamer.ts index e81edb1..2dd49b3 100644 --- a/src/destreamer.ts +++ b/src/destreamer.ts @@ -195,6 +195,9 @@ async function downloadVideo(videoUrls: string[], outputDirectories: string[], s const cleanupFn = function () { pbar.stop(); + if (argv.noCleanup) + return; + try { fs.unlinkSync(outputPath); } catch(e) {} @@ -223,11 +226,7 @@ async function downloadVideo(videoUrls: string[], outputDirectories: string[], s }); ffmpegCmd.on('error', (error: any) => { - pbar.stop(); - - try { - fs.unlinkSync(outputPath); - } catch (e) {} + cleanupFn(); console.log(`\nffmpeg returned an error: ${error.message}`); process.exit(ERROR_CODE.UNK_FFMPEG_ERROR);