Fix getDiscography() for one-album / track artists
This commit is contained in:
parent
e3260ece1c
commit
89833cef7e
|
@ -108,7 +108,9 @@ async function getTrackInfo(trackUrl, options = {}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getDiscography(artistOrLabelUrl, options = {}) {
|
async function getDiscography(artistOrLabelUrl, options = {}) {
|
||||||
|
const imageConstants = await _getImageConstants();
|
||||||
const opts = {
|
const opts = {
|
||||||
|
imageBaseUrl: imageConstants.baseUrl,
|
||||||
artistOrLabelUrl,
|
artistOrLabelUrl,
|
||||||
imageFormat: await _parseImageFormatArg(options.imageFormat)
|
imageFormat: await _parseImageFormatArg(options.imageFormat)
|
||||||
};
|
};
|
||||||
|
|
|
@ -248,9 +248,45 @@ function parseTrackInfo(html, opts) {
|
||||||
|
|
||||||
function parseDiscography(html, opts) {
|
function parseDiscography(html, opts) {
|
||||||
const $ = cheerio.load(html);
|
const $ = cheerio.load(html);
|
||||||
|
|
||||||
|
// One-album / one-track artists don't have a discography page.
|
||||||
|
// The page for the album or track will be loaded instead.
|
||||||
|
// Check if this is the case and handle accordingly
|
||||||
|
const currentAlbumOrTrack = $('script[type="application/ld+json"]');
|
||||||
|
let isOneTrack = false,
|
||||||
|
isOneAlbum = false;
|
||||||
|
if (currentAlbumOrTrack.length) {
|
||||||
|
currentAlbumOrTrackData = JSON.parse(currentAlbumOrTrack.html());
|
||||||
|
if (typeof currentAlbumOrTrackData === 'object') {
|
||||||
|
// Check if there is a 'discography' element and, if there is, whether
|
||||||
|
// it is hidden or has only one track / album child
|
||||||
|
const discographyEl = $('#discography');
|
||||||
|
if (discographyEl.length === 0 || discographyEl.css('display') === 'none' || discographyEl.find('li').length === 1) {
|
||||||
|
currentAlbumOrTrackUrl = utils.splitUrl(currentAlbumOrTrackData['@id']);
|
||||||
|
isOneTrack = currentAlbumOrTrackUrl.path.startsWith('/track/');
|
||||||
|
isOneAlbum = currentAlbumOrTrackUrl.path.startsWith('/album/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isOneTrack || isOneAlbum) {
|
||||||
|
const newOpts = {
|
||||||
|
imageBaseUrl: opts.imageBaseUrl,
|
||||||
|
albumImageFormat: opts.imageFormat,
|
||||||
|
artistImageFormat: null,
|
||||||
|
includeRawData: false
|
||||||
|
};
|
||||||
|
let info = isOneTrack ? parseTrackInfo(html, newOpts) : parseAlbumInfo(html, newOpts);
|
||||||
|
return [{
|
||||||
|
url: info.url,
|
||||||
|
type: info.type,
|
||||||
|
name: info.name || '',
|
||||||
|
imageUrl: info.imageUrl || null,
|
||||||
|
artist: info.artist.name
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
const allLinks = $('a');
|
const allLinks = $('a');
|
||||||
const items = {};
|
const items = {};
|
||||||
const isLabel = $('a[href="/artists"]').length;
|
|
||||||
const defaultArtistName = $('#band-name-location').find('.title').text();
|
const defaultArtistName = $('#band-name-location').find('.title').text();
|
||||||
allLinks.each( (index, link) => {
|
allLinks.each( (index, link) => {
|
||||||
link = $(link);
|
link = $(link);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user