getArtistOrLabelInfo(): Fix url sometimes null
This commit is contained in:
parent
9cc318c611
commit
6ae093864e
30
lib/index.js
30
lib/index.js
|
@ -182,7 +182,19 @@ async function getArtistOrLabelInfo(artistOrLabelUrl, options = {}) {
|
||||||
return _url;
|
return _url;
|
||||||
};
|
};
|
||||||
const _isInfoComplete = (data) => {
|
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();
|
let url = _getUrl();
|
||||||
|
@ -197,12 +209,7 @@ async function getArtistOrLabelInfo(artistOrLabelUrl, options = {}) {
|
||||||
url = _getUrl('music');
|
url = _getUrl('music');
|
||||||
html = await _fetchPage(url);
|
html = await _fetchPage(url);
|
||||||
let info = parser.parseArtistOrLabelInfo(html, opts);
|
let info = parser.parseArtistOrLabelInfo(html, opts);
|
||||||
if (result.name === '') {
|
_fillInfo(result, info);
|
||||||
result.name = info.name;
|
|
||||||
}
|
|
||||||
if (result.label === null) {
|
|
||||||
result.label = info.label;
|
|
||||||
}
|
|
||||||
// Return if result is complete
|
// Return if result is complete
|
||||||
if (_isInfoComplete(result)) {
|
if (_isInfoComplete(result)) {
|
||||||
return result;
|
return result;
|
||||||
|
@ -215,12 +222,11 @@ async function getArtistOrLabelInfo(artistOrLabelUrl, options = {}) {
|
||||||
url = discogItems[0].url;
|
url = discogItems[0].url;
|
||||||
html = await _fetchPage(url);
|
html = await _fetchPage(url);
|
||||||
info = parser.parseArtistOrLabelInfo(html, opts);
|
info = parser.parseArtistOrLabelInfo(html, opts);
|
||||||
if (result.name === '') {
|
_fillInfo(result, info);
|
||||||
result.name = info.name;
|
|
||||||
}
|
|
||||||
if (result.label === null) {
|
|
||||||
result.label = info.label;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result.url === null) {
|
||||||
|
result.url = artistOrLabelUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -457,10 +457,10 @@ function parseArtistOrLabelInfo(html, opts) {
|
||||||
let isLabel = bandData.is_label;
|
let isLabel = bandData.is_label;
|
||||||
const result = {
|
const result = {
|
||||||
type: isLabel ? 'label' : 'artist',
|
type: isLabel ? 'label' : 'artist',
|
||||||
name: bandData.name,
|
name: bandData.name || null,
|
||||||
url: bandData.url,
|
url: bandData.url || null,
|
||||||
description: description,
|
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)
|
imageUrl: utils.reformatImageUrl($('img.band-photo').attr('src'), opts.imageFormat)
|
||||||
};
|
};
|
||||||
if (!isLabel) {
|
if (!isLabel) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user