Change organisation scheme
This commit is contained in:
parent
7654aaa91a
commit
25a3cd56f4
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "publikator",
|
"name": "publikator",
|
||||||
"version": "0.3.0",
|
"version": "0.4.0",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"repository": "https://github.com/aengl/publikator.git",
|
"repository": "https://github.com/aengl/publikator.git",
|
||||||
"author": "Lynn Smeria <ae@cephea.de>",
|
"author": "Lynn Smeria <ae@cephea.de>",
|
||||||
|
|
|
@ -20,15 +20,13 @@ const collect = (tracks, callback) => {
|
||||||
/**
|
/**
|
||||||
* Creates release information for a single album.
|
* Creates release information for a single album.
|
||||||
*/
|
*/
|
||||||
const getAlbumInfo = tracks => {
|
const getAlbumInfo = tracks => ({
|
||||||
return {
|
|
||||||
artists: collect(tracks, t => t.common.artists || t.common.artist),
|
artists: collect(tracks, t => t.common.artists || t.common.artist),
|
||||||
album: collect(tracks, t => t.common.album),
|
album: collect(tracks, t => t.common.album),
|
||||||
bitrate: collect(tracks, t => t.format.bitrate),
|
bitrate: collect(tracks, t => t.format.bitrate),
|
||||||
trackCount: tracks.length,
|
trackCount: tracks.length,
|
||||||
tracks,
|
tracks,
|
||||||
};
|
});
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
/**
|
/**
|
||||||
|
@ -37,13 +35,14 @@ module.exports = {
|
||||||
generateReleaseInfo: taggedFiles => {
|
generateReleaseInfo: taggedFiles => {
|
||||||
const albums = _.groupBy(taggedFiles, file => path.dirname(file.path));
|
const albums = _.groupBy(taggedFiles, file => path.dirname(file.path));
|
||||||
_.forEach(albums, (albumTracks, albumRoot) => {
|
_.forEach(albums, (albumTracks, albumRoot) => {
|
||||||
|
const baseName = path.basename(albumRoot);
|
||||||
debug(
|
debug(
|
||||||
`generating release info for album '${path.basename(albumRoot)}' with ${
|
`generating release info for album '${baseName}' with ${
|
||||||
albumTracks.length
|
albumTracks.length
|
||||||
} track(s)`
|
} track(s)`
|
||||||
);
|
);
|
||||||
const releaseInfo = yaml.safeDump(getAlbumInfo(albumTracks));
|
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 debug = require('debug')('publikator:organise');
|
||||||
const tags = require('./tags');
|
const tags = require('./tags');
|
||||||
|
|
||||||
const getArtists = file => file.common.artist || file.common.artists.join(', ');
|
const getFolderName = file => file.common.album.replace(/ /g, '_');
|
||||||
const getFolderName = file => `${getArtists(file)} - ${file.common.album}`;
|
|
||||||
const getFileName = file =>
|
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 = {
|
module.exports = {
|
||||||
/**
|
/**
|
||||||
|
@ -44,13 +45,20 @@ module.exports = {
|
||||||
debug(`copying tracks`);
|
debug(`copying tracks`);
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
files.map(async file => {
|
files.map(async file => {
|
||||||
const newPath = path.resolve(
|
const folderName = getFolderName(file);
|
||||||
root,
|
const fileName = getFileName(file);
|
||||||
getFolderName(file),
|
const newPath = path.resolve(root, folderName, fileName);
|
||||||
getFileName(file)
|
|
||||||
);
|
|
||||||
await fs.copyFile(file.path, newPath);
|
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