127 lines
No EOL
4.1 KiB
JavaScript
Executable file
127 lines
No EOL
4.1 KiB
JavaScript
Executable file
#!/usr/bin/env node
|
|
|
|
// requirements
|
|
const os = require('os');
|
|
const path = require('path');
|
|
const async = require('async');
|
|
const commander = require('commander');
|
|
const app = require('./package.json');
|
|
const audio = require('./lib/audio');
|
|
const util = require('./lib/util');
|
|
const cli = require('./lib/cli');
|
|
|
|
badger();
|
|
|
|
// main application
|
|
function badger() {
|
|
cli.printLogo();
|
|
// general options
|
|
commander
|
|
.version(app.version)
|
|
.usage('[options] <command>')
|
|
.option('-c, --concurrency <n>', 'specify concurrency level', os.cpus().length)
|
|
.option('-n, --no-confirm', 'disable confirmation messages');
|
|
// conversion
|
|
commander
|
|
.command('convert <input> <output>')
|
|
.description('convert .flac to .mp3 files')
|
|
.option('-b, --bitrate <n>', 'specify conversion bitrate', 320)
|
|
.action(convert);
|
|
// sort
|
|
commander
|
|
.command('sort <input> <output>')
|
|
.description('sort audio files by tags')
|
|
.option('-f, --format <format>', 'specify audio format (\'flac\', \'mp3\')', '.flac')
|
|
.action(sort);
|
|
// artwork
|
|
commander
|
|
.command('extract <input>')
|
|
.description('extract cover artwork')
|
|
.option('-f, --format <format>', 'specify audio format (\'flac\', \'mp3\')', '.flac')
|
|
.action(extract);
|
|
// scan
|
|
commander
|
|
.command('scan <input>')
|
|
.description('scan audio files for missing cover artwork')
|
|
.option('-f, --format <format>', 'specify audio format (\'flac\', \'mp3\')', '.flac')
|
|
.action(scan);
|
|
// parse command line arguments
|
|
commander.parse(process.argv);
|
|
}
|
|
|
|
// convert files
|
|
function convert(input, output, options) {
|
|
audio.batchConvert({
|
|
input: path.normalize(input),
|
|
output: path.normalize(output),
|
|
concurrency: commander.concurrency || os.cpus().length,
|
|
confirm: commander.confirm || false,
|
|
bitrate: options.bitrate || 320,
|
|
format: options.format || '.flac'
|
|
}, function (err, time) {
|
|
cli.exit(err, time);
|
|
});
|
|
}
|
|
|
|
// sort files
|
|
function sort(input, output, options) {
|
|
util.batchSort({
|
|
input: path.normalize(input),
|
|
output: path.normalize(output),
|
|
concurrency: commander.concurrency || os.cpus().length,
|
|
confirm: commander.confirm || false,
|
|
format: options.format || '.flac'
|
|
}, function (err, skipped, time) {
|
|
if (!skipped || skipped.length === 0) {
|
|
cli.exit(err, time);
|
|
} else {
|
|
console.log(skipped.length + ' files were skipped after ' + util.getTimeDiff(time) + ' seconds');
|
|
cli.askForConfirmation('list files now?', ['yes', 'y'], function (canceled) {
|
|
if (canceled) {
|
|
cli.exit(err, time);
|
|
}
|
|
skipped.forEach(function (file) {
|
|
console.log(file);
|
|
});
|
|
cli.exit(err);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
// extract artwork
|
|
function extract(input, options) {
|
|
audio.batchArtwork({
|
|
input: path.normalize(input),
|
|
concurrency: commander.concurrency || os.cpus().length,
|
|
format: options.format || '.flac'
|
|
}, function (err, time) {
|
|
cli.exit(err, time);
|
|
});
|
|
}
|
|
|
|
// scan files
|
|
function scan(input, options) {
|
|
audio.batchScan({
|
|
input: path.normalize(input),
|
|
concurrency: commander.concurrency || os.cpus().length,
|
|
confirm: commander.confirm || false,
|
|
format: options.format || '.flac'
|
|
}, function (err, missing, time) {
|
|
if (!missing || missing.length === 0) {
|
|
console.log('no files with missing cover artwork found');
|
|
cli.exit(err, time);
|
|
} else {
|
|
console.log(missing.length + ' files with missing cover artwork found after ' + util.getTimeDiff(time) + ' seconds');
|
|
cli.askForConfirmation('list files now?', ['yes', 'y'], function (canceled) {
|
|
if (canceled) {
|
|
cli.exit(err, time);
|
|
}
|
|
missing.forEach(function (file) {
|
|
console.log(file);
|
|
});
|
|
cli.exit(err);
|
|
});
|
|
}
|
|
});
|
|
} |