From 25a3cd56f4d391db39cff6aa693bc9b24a0b3bca Mon Sep 17 00:00:00 2001 From: Lynn Smeria Date: Mon, 20 Aug 2018 14:35:21 +0200 Subject: [PATCH] Change organisation scheme --- package.json | 2 +- src/generate.js | 21 ++++++++++----------- src/organise.js | 26 +++++++++++++++++--------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index f5cf089..d2ca30c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "publikator", - "version": "0.3.0", + "version": "0.4.0", "main": "index.js", "repository": "https://github.com/aengl/publikator.git", "author": "Lynn Smeria ", diff --git a/src/generate.js b/src/generate.js index f9815bf..9ed5591 100644 --- a/src/generate.js +++ b/src/generate.js @@ -20,15 +20,13 @@ const collect = (tracks, callback) => { /** * Creates release information for a single album. */ -const getAlbumInfo = tracks => { - return { - artists: collect(tracks, t => t.common.artists || t.common.artist), - album: collect(tracks, t => t.common.album), - bitrate: collect(tracks, t => t.format.bitrate), - trackCount: tracks.length, - tracks, - }; -}; +const getAlbumInfo = tracks => ({ + artists: collect(tracks, t => t.common.artists || t.common.artist), + album: collect(tracks, t => t.common.album), + bitrate: collect(tracks, t => t.format.bitrate), + trackCount: tracks.length, + tracks, +}); module.exports = { /** @@ -37,13 +35,14 @@ module.exports = { generateReleaseInfo: taggedFiles => { const albums = _.groupBy(taggedFiles, file => path.dirname(file.path)); _.forEach(albums, (albumTracks, albumRoot) => { + const baseName = path.basename(albumRoot); debug( - `generating release info for album '${path.basename(albumRoot)}' with ${ + `generating release info for album '${baseName}' with ${ albumTracks.length } track(s)` ); const releaseInfo = yaml.safeDump(getAlbumInfo(albumTracks)); - fs.writeFileSync(path.resolve(albumRoot, 'release.yml'), releaseInfo); + fs.writeFileSync(path.resolve(albumRoot, `${baseName}.yml`), releaseInfo); }); }, }; diff --git a/src/organise.js b/src/organise.js index 8e88a91..160343b 100644 --- a/src/organise.js +++ b/src/organise.js @@ -5,10 +5,11 @@ const sanitize = require('sanitize-filename'); const debug = require('debug')('publikator:organise'); const tags = require('./tags'); -const getArtists = file => file.common.artist || file.common.artists.join(', '); -const getFolderName = file => `${getArtists(file)} - ${file.common.album}`; +const getFolderName = file => file.common.album.replace(/ /g, '_'); const getFileName = file => - `${file.common.track.no} - ${file.common.title}${path.extname(file.path)}`; + `${file.common.track.no}-${file.common.title}${path.extname( + file.path + )}`.replace(/ /g, '_'); module.exports = { /** @@ -44,13 +45,20 @@ module.exports = { debug(`copying tracks`); return Promise.all( files.map(async file => { - const newPath = path.resolve( - root, - getFolderName(file), - getFileName(file) - ); + const folderName = getFolderName(file); + const fileName = getFileName(file); + const newPath = path.resolve(root, folderName, fileName); await fs.copyFile(file.path, newPath); - return _.assign({}, file, { path: newPath }); + return _.assign( + {}, + { + path: newPath, + relativePath: `${folderName}/${fileName}`, + folderName, + fileName, + }, + _.omit(file, 'path') + ); }) ); },