Create release info for albums
This commit is contained in:
parent
15483c0354
commit
7654aaa91a
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "publikator",
|
"name": "publikator",
|
||||||
"version": "0.2.0",
|
"version": "0.3.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>",
|
||||||
|
|
|
@ -41,8 +41,7 @@ program
|
||||||
const files = scan.findFilesSync(source);
|
const files = scan.findFilesSync(source);
|
||||||
const taggedFiles = await scan.readTags(files);
|
const taggedFiles = await scan.readTags(files);
|
||||||
const organisedFiles = await organise.byAlbum(target, taggedFiles);
|
const organisedFiles = await organise.byAlbum(target, taggedFiles);
|
||||||
const releaseInfo = generate.releaseInfo(organisedFiles);
|
generate.generateReleaseInfo(organisedFiles);
|
||||||
fs.writeFileSync(path.resolve(target, 'releases.yml'), releaseInfo);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
debug(process.argv);
|
debug(process.argv);
|
||||||
|
|
|
@ -1,30 +1,49 @@
|
||||||
|
const fs = require('fs-extra');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const yaml = require('js-yaml');
|
const yaml = require('js-yaml');
|
||||||
const debug = require('debug')('publikator:generate');
|
const debug = require('debug')('publikator:generate');
|
||||||
const tags = require('./tags');
|
|
||||||
|
/**
|
||||||
|
* Collects unique values across a number of tracks.
|
||||||
|
*/
|
||||||
|
const collect = (tracks, callback) => {
|
||||||
|
const values = _.uniq(_.flatten(tracks.map(t => callback(t)))).filter(
|
||||||
|
x => !!x
|
||||||
|
);
|
||||||
|
if (values.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return values.length === 1 ? values[0] : values;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
/**
|
/**
|
||||||
* Generates a release YAML with data
|
* Generates a release YAML with data
|
||||||
*/
|
*/
|
||||||
releaseInfo: taggedFiles => {
|
generateReleaseInfo: taggedFiles => {
|
||||||
debug(`generating release info for ${taggedFiles.length} file(s)`);
|
|
||||||
const albums = _.groupBy(taggedFiles, file => path.dirname(file.path));
|
const albums = _.groupBy(taggedFiles, file => path.dirname(file.path));
|
||||||
return yaml.safeDump(
|
_.forEach(albums, (albumTracks, albumRoot) => {
|
||||||
Object.keys(albums).map(key => {
|
debug(
|
||||||
const tracks = albums[key];
|
`generating release info for album '${path.basename(albumRoot)}' with ${
|
||||||
return {
|
albumTracks.length
|
||||||
'track-count': tracks.length,
|
} track(s)`
|
||||||
tracks: tracks.map((track, i) => ({
|
);
|
||||||
path: track.path,
|
const releaseInfo = yaml.safeDump(getAlbumInfo(albumTracks));
|
||||||
position: i,
|
fs.writeFileSync(path.resolve(albumRoot, 'release.yml'), releaseInfo);
|
||||||
common: track.common,
|
});
|
||||||
format: track.format,
|
|
||||||
...tags.getTags(track, ['foo']),
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
})
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue