Change organisation scheme
This commit is contained in:
parent
7654aaa91a
commit
25a3cd56f4
|
@ -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 <ae@cephea.de>",
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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')
|
||||
);
|
||||
})
|
||||
);
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue