From 7c8138c3860bd2391e4f055e306e385d04e7e3fe Mon Sep 17 00:00:00 2001 From: Lynn Smeria Date: Mon, 20 Aug 2018 18:42:59 +0200 Subject: [PATCH] Include cover path --- package.json | 2 +- src/organise.js | 28 +++++++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 63656cf..1ee58ca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "publikator", - "version": "0.5.0", + "version": "0.6.0", "main": "index.js", "repository": "https://github.com/aengl/publikator.git", "author": "Lynn Smeria ", diff --git a/src/organise.js b/src/organise.js index 3b21913..6ca7156 100644 --- a/src/organise.js +++ b/src/organise.js @@ -19,17 +19,16 @@ const getFileName = file => const extractCoverArt = async filePath => { const pictures = await tags.extractCoverArt(filePath); if (pictures) { - await Promise.all( - pictures.map(async picture => { - const pictureExt = mime.extension(picture.format); - const picturePath = `${filePath.replace( - path.extname(filePath), - '' - )}.${pictureExt}`; - await fs.writeFile(picturePath, picture.data); - }) - ); + const picture = pictures[0]; + const pictureExt = mime.extension(picture.format); + const picturePath = `${filePath.replace( + path.extname(filePath), + '' + )}.${pictureExt}`; + await fs.writeFile(picturePath, picture.data); + return picturePath; } + return null; }; module.exports = { @@ -70,7 +69,7 @@ module.exports = { const fileName = getFileName(file); const newPath = path.resolve(root, folderName, fileName); await fs.copyFile(file.path, newPath); - await extractCoverArt(newPath); + const coverPath = await extractCoverArt(newPath); return _.assign( {}, { @@ -79,6 +78,13 @@ module.exports = { folderName, fileName, }, + coverPath + ? { + coverPath, + relativeCoverPath: `${folderName}/${path.basename(coverPath)}`, + coverFileName: path.basename(coverPath), + } + : {}, _.omit(file, 'path') ); })