mirror of
https://github.com/snobu/destreamer.git
synced 2026-02-22 06:18:25 +00:00
added quality option
This commit is contained in:
@@ -77,13 +77,11 @@ export const argv: any = yargs.options({
|
|||||||
default: false,
|
default: false,
|
||||||
demandOption: false
|
demandOption: false
|
||||||
},
|
},
|
||||||
// TODO: change this in askChoiche so that by default we download the best one
|
selectQuality: {
|
||||||
// and let the user decide if they want a particular quality with this flag
|
alias: 'q',
|
||||||
bestQuality: {
|
describe: 'Select the quality with a number 1 (worst) trough 10 (best), 0 prompt the user for each video',
|
||||||
alias: 'b',
|
default: 10,
|
||||||
describe: 'Automaticly choose the best quality aviable for video and audio',
|
type: 'number',
|
||||||
type: 'boolean',
|
|
||||||
default: false,
|
|
||||||
demandOption: false
|
demandOption: false
|
||||||
},
|
},
|
||||||
closedCaptions: {
|
closedCaptions: {
|
||||||
@@ -128,17 +126,9 @@ export const argv: any = yargs.options({
|
|||||||
.wrap(120)
|
.wrap(120)
|
||||||
.check(() => noArguments())
|
.check(() => noArguments())
|
||||||
.check((argv: any) => checkInputConflicts(argv.videoUrls, argv.inputFile))
|
.check((argv: any) => checkInputConflicts(argv.videoUrls, argv.inputFile))
|
||||||
.check((argv: any) => {
|
.check((argv: any) => checkOutputDirectoryExistance(argv.outputDirectory))
|
||||||
if (checkOutDir(argv.outputDirectory)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
logger.error(CLI_ERROR.INVALID_OUTDIR);
|
|
||||||
|
|
||||||
throw new Error(' ');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.check((argv: any) => isOutputTemplateValid(argv))
|
.check((argv: any) => isOutputTemplateValid(argv))
|
||||||
|
.check((argv: any) => checkQualityValue(argv))
|
||||||
.argv;
|
.argv;
|
||||||
|
|
||||||
|
|
||||||
@@ -188,6 +178,18 @@ function checkInputConflicts(videoUrls: Array<string | number> | undefined,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function checkOutputDirectoryExistance(dir: string): boolean {
|
||||||
|
if (checkOutDir(dir)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logger.error(CLI_ERROR.INVALID_OUTDIR, { fatal: true });
|
||||||
|
|
||||||
|
throw new Error(' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function isOutputTemplateValid(argv: any): boolean {
|
function isOutputTemplateValid(argv: any): boolean {
|
||||||
let finalTemplate: string = argv.outputTemplate;
|
let finalTemplate: string = argv.outputTemplate;
|
||||||
const elementRegEx = RegExp(/{(.*?)}/g);
|
const elementRegEx = RegExp(/{(.*?)}/g);
|
||||||
@@ -221,6 +223,25 @@ function isOutputTemplateValid(argv: any): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function checkQualityValue(argv: any): boolean {
|
||||||
|
if (isNaN(argv.selectQuality)) {
|
||||||
|
logger.error('The quality value provided was not a number, switching to default');
|
||||||
|
argv.selectQuality = 10;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (argv.selectQuality < 0 || argv.selectQuality > 10) {
|
||||||
|
logger.error('The quality value provided was outside the valid range, switching to default');
|
||||||
|
argv.selectQuality = 10;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export function promptUser(choices: Array<string>): number {
|
export function promptUser(choices: Array<string>): number {
|
||||||
let index: number = readlineSync.keyInSelect(choices, 'Which resolution/format do you prefer?');
|
let index: number = readlineSync.keyInSelect(choices, 'Which resolution/format do you prefer?');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user