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 <savicaleksa83@gmail.com>
This commit is contained in:
Don 2020-04-26 17:03:03 +02:00 committed by GitHub
parent 81a15b2023
commit 67cb62ce3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 5 deletions

View file

@ -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 -

View file

@ -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
}
})
/**

View file

@ -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);