added cli param '-n, --no-confirm'

This commit is contained in:
Daniel Sommer 2017-03-29 13:28:07 +02:00
parent ac49233bf9
commit dcd91ce8bf
4 changed files with 36 additions and 22 deletions

View file

@ -19,7 +19,8 @@ function badger() {
commander commander
.version(app.version) .version(app.version)
.usage('[options] <command>') .usage('[options] <command>')
.option('-c, --concurrency <n>', 'specify concurrency level', os.cpus().length); .option('-c, --concurrency <n>', 'specify concurrency level', os.cpus().length)
.option('-n, --no-confirm', 'disable confirmation messages');
// conversion // conversion
commander commander
.command('convert <input> <output>') .command('convert <input> <output>')
@ -54,6 +55,7 @@ function convert(input, output, options) {
input: path.normalize(input), input: path.normalize(input),
output: path.normalize(output), output: path.normalize(output),
concurrency: commander.concurrency || os.cpus().length, concurrency: commander.concurrency || os.cpus().length,
confirm: commander.confirm || false,
bitrate: options.bitrate || 320, bitrate: options.bitrate || 320,
format: options.format || '.flac' format: options.format || '.flac'
}, function (err, time) { }, function (err, time) {
@ -67,7 +69,7 @@ function sort(input, output, options) {
input: path.normalize(input), input: path.normalize(input),
output: path.normalize(output), output: path.normalize(output),
concurrency: commander.concurrency || os.cpus().length, concurrency: commander.concurrency || os.cpus().length,
bitrate: options.bitrate || 320, confirm: commander.confirm || false,
format: options.format || '.flac' format: options.format || '.flac'
}, function (err, skipped, time) { }, function (err, skipped, time) {
if (!skipped || skipped.length === 0) { if (!skipped || skipped.length === 0) {
@ -103,6 +105,7 @@ function scan(input, options) {
audio.batchScan({ audio.batchScan({
input: path.normalize(input), input: path.normalize(input),
concurrency: commander.concurrency || os.cpus().length, concurrency: commander.concurrency || os.cpus().length,
confirm: commander.confirm || false,
format: options.format || '.flac' format: options.format || '.flac'
}, function (err, missing, time) { }, function (err, missing, time) {
if (!missing || missing.length === 0) { if (!missing || missing.length === 0) {

View file

@ -19,12 +19,16 @@ function batchConvert(config, callback) {
// display info, prompt user and create progressbar // display info, prompt user and create progressbar
function (files, waterfallCallback) { function (files, waterfallCallback) {
console.log(files.length + ' files found after ' + util.getTimeDiff(timestamp) + ' seconds'); console.log(files.length + ' files found after ' + util.getTimeDiff(timestamp) + ' seconds');
if (config.confirm) {
cli.askForConfirmation('start conversion now?', ['yes', 'y'], function (err) { cli.askForConfirmation('start conversion now?', ['yes', 'y'], function (err) {
if (err) { if (err) {
return waterfallCallback(err); return waterfallCallback(err);
} }
waterfallCallback(null, files, cli.createProgressBar(files.length)); waterfallCallback(null, files, cli.createProgressBar(files.length));
}); });
} else {
waterfallCallback(null, files, cli.createProgressBar(files.length));
}
}, },
// process each file // process each file
function (files, bar, waterfallCallback) { function (files, bar, waterfallCallback) {
@ -92,12 +96,16 @@ function batchExtract(config, callback) {
// display info, prompt user and create progressbar // display info, prompt user and create progressbar
function (files, waterfallCallback) { function (files, waterfallCallback) {
console.log(files.length + ' files found after ' + util.getTimeDiff(timestamp) + ' seconds'); console.log(files.length + ' files found after ' + util.getTimeDiff(timestamp) + ' seconds');
if (config.confirm) {
cli.askForConfirmation('start artwork extraction now?', ['yes', 'y'], function (err) { cli.askForConfirmation('start artwork extraction now?', ['yes', 'y'], function (err) {
if (err) { if (err) {
return waterfallCallback(err); return waterfallCallback(err);
} }
waterfallCallback(null, files, cli.createProgressBar(files.length));
}); });
} else {
waterfallCallback(null, files, cli.createProgressBar(files.length));
}
}, },
// process each file // process each file
function (files, bar, waterfallCallback) { function (files, bar, waterfallCallback) {

View file

@ -18,12 +18,16 @@ function batchSort(config, callback) {
// display info, prompt user and create progressbar // display info, prompt user and create progressbar
function (files, waterfallCallback) { function (files, waterfallCallback) {
console.log(files.length + ' files found after ' + getTimeDiff(timestamp) + ' seconds'); console.log(files.length + ' files found after ' + getTimeDiff(timestamp) + ' seconds');
if (config.confirm) {
cli.askForConfirmation('start sorting now?', ['yes', 'y'], function (err) { cli.askForConfirmation('start sorting now?', ['yes', 'y'], function (err) {
if (err) { if (err) {
return waterfallCallback(err); return waterfallCallback(err);
} }
waterfallCallback(null, files, cli.createProgressBar(files.length)); waterfallCallback(null, files, cli.createProgressBar(files.length));
}); });
} else {
waterfallCallback(null, files, cli.createProgressBar(files.length));
}
}, },
// process each file // process each file
function (files, bar, waterfallCallback) { function (files, bar, waterfallCallback) {
@ -125,9 +129,9 @@ function getPathByMetadata(source, output, metadata, callback) {
fileName += metadata.title.trim(); fileName += metadata.title.trim();
} }
// append extension // append extension
fileName += replaceIllegalChars(path.extname(source)).trim(); fileName += path.extname(source).trim();
// join directory and name // replace illegal chars, join directory and name
callback(null, path.join(filePath, fileName)); callback(null, path.join(filePath, replaceIllegalChars(fileName)));
} }
// fill a string beginning from the front // fill a string beginning from the front
@ -140,7 +144,6 @@ function frontFill(string, fill, length) {
// replace illegal characters // replace illegal characters
function replaceIllegalChars(string) { function replaceIllegalChars(string) {
// TODO: check function, seems like it doesn't work at all
return string.replace(/[/\\:*?"<>|]/g, '-'); return string.replace(/[/\\:*?"<>|]/g, '-');
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "badger-am", "name": "badger-am",
"version": "0.6.1", "version": "0.7.0",
"license": "MIT", "license": "MIT",
"description": "audio manager", "description": "audio manager",
"author": "Daniel Sommer <daniel.sommer@velvettear.de>", "author": "Daniel Sommer <daniel.sommer@velvettear.de>",