88 lines
2.4 KiB
JavaScript
Executable file
88 lines
2.4 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');
|
|
|
|
// generate timestamp
|
|
const start = process.hrtime();
|
|
|
|
badger();
|
|
|
|
// "main"
|
|
function badger() {
|
|
cli.printLogo();
|
|
run();
|
|
}
|
|
|
|
// start from command lines
|
|
function run() {
|
|
// general options
|
|
commander
|
|
.version(app.version)
|
|
.usage('[options] <command>')
|
|
.option('-c, --concurrency <n>', 'specify concurrency level', os.cpus().length);
|
|
// 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 <type>', 'specify audio format (\'flac\', \'mp3\')', '.flac')
|
|
.action(sort);
|
|
// artwork
|
|
commander
|
|
.command('artwork <input>')
|
|
.description('extract cover artwork')
|
|
.option('-f, --format <type>', 'specify audio format (\'flac\', \'mp3\')', '.flac')
|
|
.action(artwork);
|
|
// 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,
|
|
bitrate: options.bitrate || 320,
|
|
format: options.format || '.flac'
|
|
}, function (err) {
|
|
cli.exit(err);
|
|
});
|
|
}
|
|
|
|
// sort files
|
|
function sort(input, output, options) {
|
|
util.batchSort({
|
|
input: path.normalize(input),
|
|
output: path.normalize(output),
|
|
concurrency: commander.concurrency || os.cpus().length,
|
|
bitrate: options.bitrate || 320,
|
|
format: options.format || '.flac'
|
|
}, function (err) {
|
|
cli.exit(err);
|
|
});
|
|
}
|
|
|
|
// extract artwork
|
|
function artwork(input, options) {
|
|
audio.batchArtwork({
|
|
input: path.normalize(input),
|
|
concurrency: commander.concurrency || os.cpus().length,
|
|
format: options.format || '.flac'
|
|
}, function (err) {
|
|
cli.exit(err);
|
|
});
|
|
} |