More robust fetching of artist / label info
This commit is contained in:
parent
ee34118b7d
commit
5674fd1cc0
28
lib/index.js
28
lib/index.js
|
@ -192,11 +192,35 @@ async function getArtistOrLabelInfo(artistOrLabelUrl, options = {}) {
|
||||||
artistOrLabelUrl,
|
artistOrLabelUrl,
|
||||||
imageFormat: await _parseImageFormatArg(options.imageFormat)
|
imageFormat: await _parseImageFormatArg(options.imageFormat)
|
||||||
};
|
};
|
||||||
// Some pages don't actually show the 'bio' column.
|
// The landing page of some artists and labels don't actually
|
||||||
// The /music page does seem to always show it though, so parse from that.
|
// contain the 'bio' column, so we fetch from the
|
||||||
|
// 'music' page instead. For artists, if the 'music' page does not
|
||||||
|
// have the artist info, we shall try with an album or track page
|
||||||
|
// (this is inefficient...perhaps there is a better way?).
|
||||||
return fetch(utils.getUrl('music', artistOrLabelUrl))
|
return fetch(utils.getUrl('music', artistOrLabelUrl))
|
||||||
|
.then( res => res.text() )
|
||||||
|
.then( html => parser.parseArtistOrLabelInfo(html, opts) )
|
||||||
|
.then( info => {
|
||||||
|
if (info.type === 'label' || info.name !== '') {
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return getDiscography(artistOrLabelUrl, options)
|
||||||
|
.then( discographyItems => {
|
||||||
|
const firstAlbumOrTrack = discographyItems[0];
|
||||||
|
if (firstAlbumOrTrack) {
|
||||||
|
return firstAlbumOrTrack.url;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// fallback
|
||||||
|
return artistOrLabelUrl;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then( url => fetch(url) )
|
||||||
.then( res => res.text() )
|
.then( res => res.text() )
|
||||||
.then( html => parser.parseArtistOrLabelInfo(html, opts) );
|
.then( html => parser.parseArtistOrLabelInfo(html, opts) );
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getLabelArtists(labelUrl, options = {}) {
|
async function getLabelArtists(labelUrl, options = {}) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user