getArtistOrLabelInfo(): Fix url sometimes null

This commit is contained in:
patrickkfkan 2021-10-20 18:53:01 +08:00
parent 9cc318c611
commit 6ae093864e
2 changed files with 22 additions and 16 deletions

View File

@ -182,7 +182,19 @@ async function getArtistOrLabelInfo(artistOrLabelUrl, options = {}) {
return _url;
};
const _isInfoComplete = (data) => {
return data.name !== '' && (data.type === 'label' || data.label !== null);
return data.name !== null && data.url !== null &&
(data.type === 'label' || data.label !== null);
}
const _fillInfo = (toData, fromData) => {
if (toData.name === null) {
toData.name = fromData.name;
}
if (toData.url === null) {
toData.url = fromData.url;
}
if (toData.label === null) {
toData.label = fromData.label;
}
}
let url = _getUrl();
@ -197,12 +209,7 @@ async function getArtistOrLabelInfo(artistOrLabelUrl, options = {}) {
url = _getUrl('music');
html = await _fetchPage(url);
let info = parser.parseArtistOrLabelInfo(html, opts);
if (result.name === '') {
result.name = info.name;
}
if (result.label === null) {
result.label = info.label;
}
_fillInfo(result, info);
// Return if result is complete
if (_isInfoComplete(result)) {
return result;
@ -215,12 +222,11 @@ async function getArtistOrLabelInfo(artistOrLabelUrl, options = {}) {
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;
}
_fillInfo(result, info);
}
if (result.url === null) {
result.url = artistOrLabelUrl;
}
return result;

View File

@ -457,10 +457,10 @@ function parseArtistOrLabelInfo(html, opts) {
let isLabel = bandData.is_label;
const result = {
type: isLabel ? 'label' : 'artist',
name: bandData.name,
url: bandData.url,
name: bandData.name || null,
url: bandData.url || null,
description: description,
location: $('#band-name-location').find('.location').text(),
location: $('#band-name-location').find('.location').text() || '',
imageUrl: utils.reformatImageUrl($('img.band-photo').attr('src'), opts.imageFormat)
};
if (!isLabel) {