From 5d74221deb76f562483bd11cd43aad820f797706 Mon Sep 17 00:00:00 2001 From: velvettear Date: Tue, 28 Mar 2017 13:50:31 +0200 Subject: [PATCH] bugfixes and improvements --- lib/cli.js | 1 + lib/util.js | 32 ++++++++++++++++++++++---------- package.json | 2 +- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 8098dbf..0100a36 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -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 + '\''); } diff --git a/lib/util.js b/lib/util.js index edf4316..a6ccec2 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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) { diff --git a/package.json b/package.json index 218c8af..5b4333a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "badger-am", - "version": "0.5.2", + "version": "0.5.3", "license": "MIT", "description": "audio manager", "author": "Daniel Sommer ",