getArtistOrLabelInfo(): Fix url sometimes null
This commit is contained in:
parent
9cc318c611
commit
6ae093864e
32
lib/index.js
32
lib/index.js
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user