From ccc171237dc4fa512e728ef488f15a6f6e99c31c Mon Sep 17 00:00:00 2001 From: Angelo B <43997819+angelobpool@users.noreply.github.com> Date: Sat, 21 Mar 2020 17:10:33 +0100 Subject: [PATCH] Added audio/video quality option Exposed native youtube-dl option "--format", that gives the ability to choose audio/video format and quality. --- destreamer.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/destreamer.ts b/destreamer.ts index 753fd05..31ff402 100644 --- a/destreamer.ts +++ b/destreamer.ts @@ -13,12 +13,18 @@ const args: string[] = process.argv.slice(2); // TODO: Remove this const argv = yargs.options({ videoUrls: { type: 'array', demandOption: true }, username: { type: 'string', demandOption: true }, - outputDirectory: { type: 'string', default: 'videos' } + outputDirectory: { type: 'string', default: 'videos' }, + format: {alias:"f", + describe: 'Expose youtube-dl --format option, for details see\n https://github.com/ytdl-org/youtube-dl/blob/master/README.md#format-selection', + type:'string', + default:'best' + } }).argv; console.info('Video URLs: %s', argv.videoUrls); console.info('Username: %s', argv.username); console.info('Output Directory: %s', argv.outputDirectory); +console.info('Video/Audio Quality: %s', argv.format); function sanityChecks() { try { @@ -103,7 +109,7 @@ async function rentVideoForLater(videoUrls: string[], username: string, outputDi console.log('Spawning youtube-dl with cookie and HLS URL...'); const youtubedlCmd = 'youtube-dl --no-call-home --no-warnings ' + - `--output "${outputDirectory}/${title}.mp4" --add-header Cookie:"${cookie}" "${hlsUrl}"`; + `-f "${argv.format}" --output "${outputDirectory}/${title}.mp4" --add-header Cookie:"${cookie}" "${hlsUrl}"`; // console.log(`\n\n[DEBUG] Invoking youtube-dl: ${youtubedlCmd}\n\n`); var result = execSync(youtubedlCmd, { stdio: 'inherit' }); } @@ -145,4 +151,4 @@ if (args[0] === 'test') else { sanityChecks(); rentVideoForLater(argv.videoUrls as string[], argv.username, argv.outputDirectory); -} \ No newline at end of file +}