Parse and normalise dates
This commit is contained in:
parent
423bfe47d8
commit
a0cc2e4927
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "publikator",
|
"name": "publikator",
|
||||||
"version": "0.17.5",
|
"version": "0.17.7",
|
||||||
"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>",
|
||||||
|
|
|
@ -23,6 +23,18 @@ const collect = (tracks, callback) => {
|
||||||
const find = (tracks, path) =>
|
const find = (tracks, path) =>
|
||||||
_.get(tracks.find(track => !_.isNil(_.get(track, path))), path);
|
_.get(tracks.find(track => !_.isNil(_.get(track, path))), path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a date and returns it in the form of `year-month-day`.
|
||||||
|
*/
|
||||||
|
const parseDate = s => {
|
||||||
|
if (!_.isNil(s)) {
|
||||||
|
const d = new Date(s.toString());
|
||||||
|
if (!_.isNaN(d.getTime())) {
|
||||||
|
return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates release information for a single album.
|
* Creates release information for a single album.
|
||||||
*/
|
*/
|
||||||
|
@ -34,13 +46,14 @@ const getAlbumInfo = (root, tracks) => ({
|
||||||
bitrate: collect(tracks, t => t.format.bitrate),
|
bitrate: collect(tracks, t => t.format.bitrate),
|
||||||
trackCount: tracks.length,
|
trackCount: tracks.length,
|
||||||
cover: find(tracks, 'cover'),
|
cover: find(tracks, 'cover'),
|
||||||
date:
|
date: parseDate(
|
||||||
find(tracks, 'common.date') ||
|
find(tracks, 'common.date') ||
|
||||||
find(tracks, 'common.originaldate') ||
|
find(tracks, 'common.originaldate') ||
|
||||||
find(tracks, 'all.ORIGINALDATE') ||
|
find(tracks, 'all.ORIGINALDATE') ||
|
||||||
find(tracks, 'common.year') ||
|
find(tracks, 'common.year') ||
|
||||||
find(tracks, 'common.originalyear') ||
|
find(tracks, 'common.originalyear') ||
|
||||||
find(tracks, 'all.ORIGINALYEAR'),
|
find(tracks, 'all.ORIGINALYEAR')
|
||||||
|
),
|
||||||
tracks: _.sortBy(tracks, 'common.track.no'),
|
tracks: _.sortBy(tracks, 'common.track.no'),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue