diff --git a/lib/index.js b/lib/index.js index a9c0a19..ad29ba8 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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 = {}) {