From 3b48221d27143cbbee917ee5a5812cc03cd9aabc Mon Sep 17 00:00:00 2001 From: kylon Date: Thu, 16 Apr 2020 18:36:36 +0200 Subject: [PATCH] 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...