getArtistOrLabelInfo(): more complete fetching
This commit is contained in:
parent
279e86a58e
commit
c1590e150f
79
lib/index.js
79
lib/index.js
|
@ -174,37 +174,56 @@ async function getArtistOrLabelInfo(artistOrLabelUrl, options = {}) {
|
||||||
artistOrLabelUrl,
|
artistOrLabelUrl,
|
||||||
imageFormat: await _parseImageFormatArg(options.imageFormat)
|
imageFormat: await _parseImageFormatArg(options.imageFormat)
|
||||||
};
|
};
|
||||||
let url = utils.getUrl('music', artistOrLabelUrl);
|
const _getUrl = (path) => {
|
||||||
if (options.labelId) {
|
let _url = path ? utils.getUrl(path, artistOrLabelUrl) : artistOrLabelUrl;
|
||||||
url += '/?label=' + encodeURIComponent(options.labelId);
|
if (options.labelId) {
|
||||||
|
_url += '/?label=' + encodeURIComponent(options.labelId);
|
||||||
|
}
|
||||||
|
return _url;
|
||||||
|
};
|
||||||
|
const _isInfoComplete = (data) => {
|
||||||
|
return data.name !== '' && (data.type === 'label' || data.label !== null);
|
||||||
}
|
}
|
||||||
// The landing page of some artists and labels don't actually
|
|
||||||
// contain the 'bio' column, so we fetch from the
|
let url = _getUrl();
|
||||||
// 'music' page instead. For artists, if the 'music' page does not
|
let html = await _fetchPage(url);
|
||||||
// have the artist info, we shall try with an album or track page
|
let result = parser.parseArtistOrLabelInfo(html, opts);
|
||||||
// (this is inefficient...perhaps there is a better way?).
|
// Return if result is complete
|
||||||
return _fetchPage(url)
|
if (_isInfoComplete(result)) {
|
||||||
.then( html => parser.parseArtistOrLabelInfo(html, opts) )
|
return result;
|
||||||
.then( info => {
|
}
|
||||||
if (info.type === 'label' || info.name !== '') {
|
|
||||||
return info;
|
// Info lacking name or label (for artist) - try getting them from music page
|
||||||
}
|
url = _getUrl('music');
|
||||||
else {
|
html = await _fetchPage(url);
|
||||||
return getDiscography(artistOrLabelUrl, options)
|
let info = parser.parseArtistOrLabelInfo(html, opts);
|
||||||
.then( discographyItems => {
|
if (result.name === '') {
|
||||||
const firstAlbumOrTrack = discographyItems[0];
|
result.name = info.name;
|
||||||
if (firstAlbumOrTrack) {
|
}
|
||||||
return firstAlbumOrTrack.url;
|
if (result.label === null) {
|
||||||
}
|
result.label = info.label;
|
||||||
else {
|
}
|
||||||
// fallback
|
// Return if result is complete
|
||||||
return artistOrLabelUrl;
|
if (_isInfoComplete(result)) {
|
||||||
}
|
return result;
|
||||||
})
|
}
|
||||||
.then( url => _fetchPage(url) )
|
|
||||||
.then( html => parser.parseArtistOrLabelInfo(html, opts) );
|
// Info is still lacking name or label (for artist) - last try with fetching
|
||||||
}
|
// from discog's first album or track
|
||||||
});
|
let discogItems = await getDiscography(artistOrLabelUrl, options);
|
||||||
|
if (discogItems[0]) {
|
||||||
|
url = discogItems[0].url;
|
||||||
|
html = await _fetchPage(url);
|
||||||
|
info = parser.parseArtistOrLabelInfo(html, opts);
|
||||||
|
if (result.name === '') {
|
||||||
|
result.name = info.name;
|
||||||
|
}
|
||||||
|
if (result.label === null) {
|
||||||
|
result.label = info.label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getLabelArtists(labelUrl, options = {}) {
|
async function getLabelArtists(labelUrl, options = {}) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user