bugfixes and improvements

This commit is contained in:
Daniel Sommer 2017-03-28 13:50:31 +02:00
parent 33c725f7ae
commit 5d74221deb
3 changed files with 24 additions and 11 deletions

View file

@ -27,6 +27,7 @@ function askForConfirmation(message, confirms, callback) {
}
message += ']';
line.question(message + '\n', function (answer) {
line.close();
if (confirms.indexOf(answer) === -1) {
return callback('wrong input: \'' + answer + '\'');
}

View file

@ -20,7 +20,7 @@ function batchSort(config, callback) {
if (err) {
return waterfallCallback(err);
}
waterfallCallback(null, files, cli.createProgressBar(files.length));
waterfallCallback(null, files, cli.createProgressBar(files.length));
});
},
// process each file
@ -60,7 +60,16 @@ function moveFile(source, config, callback) {
},
// move file
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);
}
@ -71,20 +80,19 @@ function getPathByMetadata(source, output, metadata, callback) {
let filePath = path.normalize(output);
if (metadata.albumartist && metadata.albumartist.length > 0) {
let tmp;
const artistCount = metadata.albumartist.length;
for (let counter = 0; counter < artistCount; counter++) {
for (let counter = 0, length = metadata.albumartist.length; counter < length; counter++) {
if (counter > 0) {
tmp += ' - ' + metadata.albumartist[counter];
} else {
tmp = metadata.albumartist[counter];
}
}
filePath = path.join(filePath, tmp);
filePath = path.join(filePath, replaceSpecialChars(tmp.trim()));
} else {
filePath = path.join(filePath, metadata.artist[0]);
filePath = path.join(filePath, replaceSpecialChars(metadata.artist[0].trim()));
}
if (metadata.album) {
filePath = path.join(filePath, metadata.album);
filePath = path.join(filePath, replaceSpecialChars(metadata.album.trim()));
}
// define filename
let fileName = '';
@ -99,13 +107,13 @@ function getPathByMetadata(source, output, metadata, callback) {
}
}
if (metadata.artist) {
fileName += metadata.artist[0] + ' - ';
fileName += metadata.artist[0].trim() + ' - ';
}
if (metadata.title) {
fileName += metadata.title;
fileName += metadata.title.trim();
}
// append extension
fileName += path.extname(source);
fileName += replaceSpecialChars(path.extname(source)).trim();
// join directory and name
callback(null, path.join(filePath, fileName));
}
@ -118,6 +126,10 @@ function frontFill(string, fill, length) {
return string;
}
function replaceSpecialChars(string) {
return string.replace(/[/\\:*?"<>|]/g, '-');
}
// list files in directory
function readDirRecursive(where, extension, callback) {
if (extension.indexOf('.') !== 0) {

View file

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