bugfixes and improvements
This commit is contained in:
parent
33c725f7ae
commit
5d74221deb
|
@ -27,6 +27,7 @@ function askForConfirmation(message, confirms, callback) {
|
||||||
}
|
}
|
||||||
message += ']';
|
message += ']';
|
||||||
line.question(message + '\n', function (answer) {
|
line.question(message + '\n', function (answer) {
|
||||||
|
line.close();
|
||||||
if (confirms.indexOf(answer) === -1) {
|
if (confirms.indexOf(answer) === -1) {
|
||||||
return callback('wrong input: \'' + answer + '\'');
|
return callback('wrong input: \'' + answer + '\'');
|
||||||
}
|
}
|
||||||
|
|
32
lib/util.js
32
lib/util.js
|
@ -20,7 +20,7 @@ function batchSort(config, callback) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return waterfallCallback(err);
|
return waterfallCallback(err);
|
||||||
}
|
}
|
||||||
waterfallCallback(null, files, cli.createProgressBar(files.length));
|
waterfallCallback(null, files, cli.createProgressBar(files.length));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// process each file
|
// process each file
|
||||||
|
@ -60,7 +60,16 @@ function moveFile(source, config, callback) {
|
||||||
},
|
},
|
||||||
// move file
|
// move file
|
||||||
function (target, waterfallCallback) {
|
function (target, waterfallCallback) {
|
||||||
fse.move(source, target, waterfallCallback);
|
fse.move(source, target, function (err) {
|
||||||
|
if (err) {
|
||||||
|
if (err.code === 'EEXIST') {
|
||||||
|
console.log('file already exists, skipping ...');
|
||||||
|
} else {
|
||||||
|
return waterfallCallback(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
waterfallCallback();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
], callback);
|
], callback);
|
||||||
}
|
}
|
||||||
|
@ -71,20 +80,19 @@ function getPathByMetadata(source, output, metadata, callback) {
|
||||||
let filePath = path.normalize(output);
|
let filePath = path.normalize(output);
|
||||||
if (metadata.albumartist && metadata.albumartist.length > 0) {
|
if (metadata.albumartist && metadata.albumartist.length > 0) {
|
||||||
let tmp;
|
let tmp;
|
||||||
const artistCount = metadata.albumartist.length;
|
for (let counter = 0, length = metadata.albumartist.length; counter < length; counter++) {
|
||||||
for (let counter = 0; counter < artistCount; counter++) {
|
|
||||||
if (counter > 0) {
|
if (counter > 0) {
|
||||||
tmp += ' - ' + metadata.albumartist[counter];
|
tmp += ' - ' + metadata.albumartist[counter];
|
||||||
} else {
|
} else {
|
||||||
tmp = metadata.albumartist[counter];
|
tmp = metadata.albumartist[counter];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
filePath = path.join(filePath, tmp);
|
filePath = path.join(filePath, replaceSpecialChars(tmp.trim()));
|
||||||
} else {
|
} else {
|
||||||
filePath = path.join(filePath, metadata.artist[0]);
|
filePath = path.join(filePath, replaceSpecialChars(metadata.artist[0].trim()));
|
||||||
}
|
}
|
||||||
if (metadata.album) {
|
if (metadata.album) {
|
||||||
filePath = path.join(filePath, metadata.album);
|
filePath = path.join(filePath, replaceSpecialChars(metadata.album.trim()));
|
||||||
}
|
}
|
||||||
// define filename
|
// define filename
|
||||||
let fileName = '';
|
let fileName = '';
|
||||||
|
@ -99,13 +107,13 @@ function getPathByMetadata(source, output, metadata, callback) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (metadata.artist) {
|
if (metadata.artist) {
|
||||||
fileName += metadata.artist[0] + ' - ';
|
fileName += metadata.artist[0].trim() + ' - ';
|
||||||
}
|
}
|
||||||
if (metadata.title) {
|
if (metadata.title) {
|
||||||
fileName += metadata.title;
|
fileName += metadata.title.trim();
|
||||||
}
|
}
|
||||||
// append extension
|
// append extension
|
||||||
fileName += path.extname(source);
|
fileName += replaceSpecialChars(path.extname(source)).trim();
|
||||||
// join directory and name
|
// join directory and name
|
||||||
callback(null, path.join(filePath, fileName));
|
callback(null, path.join(filePath, fileName));
|
||||||
}
|
}
|
||||||
|
@ -118,6 +126,10 @@ function frontFill(string, fill, length) {
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function replaceSpecialChars(string) {
|
||||||
|
return string.replace(/[/\\:*?"<>|]/g, '-');
|
||||||
|
}
|
||||||
|
|
||||||
// list files in directory
|
// list files in directory
|
||||||
function readDirRecursive(where, extension, callback) {
|
function readDirRecursive(where, extension, callback) {
|
||||||
if (extension.indexOf('.') !== 0) {
|
if (extension.indexOf('.') !== 0) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "badger-am",
|
"name": "badger-am",
|
||||||
"version": "0.5.2",
|
"version": "0.5.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "audio manager",
|
"description": "audio manager",
|
||||||
"author": "Daniel Sommer <daniel.sommer@velvettear.de>",
|
"author": "Daniel Sommer <daniel.sommer@velvettear.de>",
|
||||||
|
|
Loading…
Reference in a new issue