More robust fetching of artist / label info

This commit is contained in:
patrickkfkan 2021-01-25 23:44:54 +08:00
parent ee34118b7d
commit 5674fd1cc0

View File

@ -192,11 +192,35 @@ async function getArtistOrLabelInfo(artistOrLabelUrl, options = {}) {
artistOrLabelUrl,
imageFormat: await _parseImageFormatArg(options.imageFormat)
};
// Some pages don't actually show the 'bio' column.
// The /music page does seem to always show it though, so parse from that.
// The landing page of some artists and labels don't actually
// 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))
.then( res => res.text() )
.then( html => parser.parseArtistOrLabelInfo(html, opts) );
.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( html => parser.parseArtistOrLabelInfo(html, opts) );
}
});
}
async function getLabelArtists(labelUrl, options = {}) {