Adapt bc changes; add 'label' + 'publisher' props
This commit is contained in:
parent
12255e18de
commit
fd2e18c696
|
@ -174,12 +174,16 @@ async function getArtistOrLabelInfo(artistOrLabelUrl, options = {}) {
|
||||||
artistOrLabelUrl,
|
artistOrLabelUrl,
|
||||||
imageFormat: await _parseImageFormatArg(options.imageFormat)
|
imageFormat: await _parseImageFormatArg(options.imageFormat)
|
||||||
};
|
};
|
||||||
|
let url = utils.getUrl('music', artistOrLabelUrl);
|
||||||
|
if (options.labelId) {
|
||||||
|
url += '/?label=' + encodeURIComponent(options.labelId);
|
||||||
|
}
|
||||||
// The landing page of some artists and labels don't actually
|
// The landing page of some artists and labels don't actually
|
||||||
// contain the 'bio' column, so we fetch from the
|
// contain the 'bio' column, so we fetch from the
|
||||||
// 'music' page instead. For artists, if the 'music' page does not
|
// 'music' page instead. For artists, if the 'music' page does not
|
||||||
// have the artist info, we shall try with an album or track page
|
// have the artist info, we shall try with an album or track page
|
||||||
// (this is inefficient...perhaps there is a better way?).
|
// (this is inefficient...perhaps there is a better way?).
|
||||||
return _fetchPage(utils.getUrl('music', artistOrLabelUrl))
|
return _fetchPage(url)
|
||||||
.then( html => parser.parseArtistOrLabelInfo(html, opts) )
|
.then( html => parser.parseArtistOrLabelInfo(html, opts) )
|
||||||
.then( info => {
|
.then( info => {
|
||||||
if (info.type === 'label' || info.name !== '') {
|
if (info.type === 'label' || info.name !== '') {
|
||||||
|
|
148
lib/parser.js
148
lib/parser.js
|
@ -145,44 +145,59 @@ function parseAlbumInfo(html, opts) {
|
||||||
numTracks: basic.numTracks,
|
numTracks: basic.numTracks,
|
||||||
imageUrl: utils.reformatImageUrl(basic.image, opts.albumImageFormat),
|
imageUrl: utils.reformatImageUrl(basic.image, opts.albumImageFormat),
|
||||||
keywords: basic.keywords,
|
keywords: basic.keywords,
|
||||||
description: basic.description,
|
description: basic.description || '',
|
||||||
releaseDate: extra.album_release_date,
|
releaseDate: extra.album_release_date,
|
||||||
artist: {
|
artist: {
|
||||||
name: basic.byArtist.name,
|
name: basic.byArtist.name,
|
||||||
url: basic.byArtist['@id'],
|
url: basic.byArtist['@id'] || null,
|
||||||
description: basic.byArtist.description,
|
description: null,
|
||||||
imageUrl: utils.reformatImageUrl(basic.byArtist.image, opts.artistImageFormat)
|
imageUrl: null,
|
||||||
},
|
},
|
||||||
|
publisher: null,
|
||||||
|
label: _parseBackToLabelLink($),
|
||||||
releases: [],
|
releases: [],
|
||||||
tracks: []
|
tracks: []
|
||||||
};
|
};
|
||||||
|
_setPublisher(album, basic, opts.artistImageFormat);
|
||||||
|
|
||||||
if (Array.isArray(basic.albumRelease)) {
|
if (Array.isArray(basic.albumRelease)) {
|
||||||
basic.albumRelease.forEach( release => {
|
basic.albumRelease.filter( release => release.musicReleaseFormat ).forEach( release => {
|
||||||
const releaseItem = {
|
const releaseItem = {
|
||||||
name: release.name,
|
name: release.name,
|
||||||
url: null,
|
url: null,
|
||||||
format: release.musicReleaseFormat,
|
format: release.musicReleaseFormat,
|
||||||
description: release.description || '',
|
description: release.description || '',
|
||||||
imageUrl: utils.reformatImageUrl(release.image, opts.albumImageFormat)
|
imageUrl: null
|
||||||
}
|
}
|
||||||
if (release.url) {
|
if (release['@id']) {
|
||||||
releaseItem.url = !utils.isAbsoluteUrl(release.url) ? utils.getUrl(release.url, album.url) : release.url;
|
releaseItem.url = !utils.isAbsoluteUrl(release['@id']) ? utils.getUrl(release['@id'], album.url) : release['@id'];
|
||||||
|
}
|
||||||
|
if (release.image) {
|
||||||
|
if (Array.isArray(release.image) && release.image[0]) {
|
||||||
|
releaseItem.imageUrl = release.image[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let releaseImageArtId = getAdditionalPropertyValue(release, 'art_id');
|
||||||
|
if (releaseImageArtId) {
|
||||||
|
opts.imageBaseUrl + '/img/a' + releaseImageArtId + '_' + opts.albumImageFormat.id + '.jpg'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
album.releases.push(releaseItem);
|
album.releases.push(releaseItem);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (Array.isArray(basic.track.itemListElement)) {
|
if (Array.isArray(extra.trackinfo)) {
|
||||||
basic.track.itemListElement.forEach( track => {
|
extra.trackinfo.forEach( track => {
|
||||||
let trackUrl = track.item['@id'];
|
let trackUrl = track.title_link;
|
||||||
if (!utils.isAbsoluteUrl(trackUrl)) {
|
if (!utils.isAbsoluteUrl(trackUrl)) {
|
||||||
trackUrl = utils.getUrl(trackUrl, album.url);
|
trackUrl = utils.getUrl(trackUrl, album.url);
|
||||||
}
|
}
|
||||||
album.tracks.push({
|
album.tracks.push({
|
||||||
position: track.position,
|
position: track.track_num,
|
||||||
name: track.item.name,
|
name: track.title,
|
||||||
url: trackUrl,
|
url: trackUrl,
|
||||||
duration: getAdditionalPropertyValue(track.item, 'duration_secs'),
|
duration: track.duration,
|
||||||
streamUrl: getAdditionalPropertyValue(track.item, 'file_mp3-128') || null
|
streamUrl: (track.file && track.file['mp3-128']) || null
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -227,15 +242,27 @@ function parseTrackInfo(html, opts) {
|
||||||
releaseDate: extra.current.release_date,
|
releaseDate: extra.current.release_date,
|
||||||
duration: getAdditionalPropertyValue(basic, 'duration_secs'),
|
duration: getAdditionalPropertyValue(basic, 'duration_secs'),
|
||||||
streamUrl: extra.trackinfo && extra.trackinfo[0] && extra.trackinfo[0].file && extra.trackinfo[0].file['mp3-128'] ? extra.trackinfo[0].file['mp3-128'] : null,
|
streamUrl: extra.trackinfo && extra.trackinfo[0] && extra.trackinfo[0].file && extra.trackinfo[0].file['mp3-128'] ? extra.trackinfo[0].file['mp3-128'] : null,
|
||||||
artist: {
|
artist: null,
|
||||||
name: basic.byArtist.name,
|
publisher: null,
|
||||||
url: basic.byArtist['@id'],
|
label: _parseBackToLabelLink($),
|
||||||
description: basic.byArtist.description,
|
|
||||||
imageUrl: utils.reformatImageUrl(basic.byArtist.image, opts.artistImageFormat)
|
|
||||||
},
|
|
||||||
album: null
|
album: null
|
||||||
}
|
}
|
||||||
if (basic.inAlbum) {
|
let byArtist;
|
||||||
|
if (basic.inAlbum && basic.inAlbum.byArtist) {
|
||||||
|
byArtist = basic.inAlbum.byArtist;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
byArtist = basic.byArtist;
|
||||||
|
}
|
||||||
|
track.artist = {
|
||||||
|
name: byArtist.name,
|
||||||
|
url: byArtist['@id'] || null,
|
||||||
|
description: null,
|
||||||
|
imageUrl: null
|
||||||
|
}
|
||||||
|
_setPublisher(track, basic, opts.artistImageFormat);
|
||||||
|
|
||||||
|
if (basic.inAlbum && basic.inAlbum['@id']) {
|
||||||
track.album = {
|
track.album = {
|
||||||
name: basic.inAlbum.name,
|
name: basic.inAlbum.name,
|
||||||
url: basic.inAlbum['@id'],
|
url: basic.inAlbum['@id'],
|
||||||
|
@ -266,12 +293,9 @@ function parseTrackInfoFromAlbum(html, opts, trackPosition) {
|
||||||
releaseDate: album.releaseDate,
|
releaseDate: album.releaseDate,
|
||||||
duration: trackData.duration,
|
duration: trackData.duration,
|
||||||
streamUrl: trackData.streamUrl,
|
streamUrl: trackData.streamUrl,
|
||||||
artist: {
|
artist: album.artist,
|
||||||
name: album.artist.name,
|
publisher: album.publisher,
|
||||||
url: album.artist.url,
|
label: album.label,
|
||||||
description: album.artist.description,
|
|
||||||
imageUrl: album.artist.imageUrl
|
|
||||||
},
|
|
||||||
album: {
|
album: {
|
||||||
name: album.name,
|
name: album.name,
|
||||||
url: album.url,
|
url: album.url,
|
||||||
|
@ -407,6 +431,7 @@ function parseDiscography(html, opts) {
|
||||||
|
|
||||||
function parseArtistOrLabelInfo(html, opts) {
|
function parseArtistOrLabelInfo(html, opts) {
|
||||||
const $ = cheerio.load(html);
|
const $ = cheerio.load(html);
|
||||||
|
const bandData = JSON.parse(decode($('script[data-band]').attr('data-band')));
|
||||||
|
|
||||||
let bioText = $('#bio-text');
|
let bioText = $('#bio-text');
|
||||||
let description;
|
let description;
|
||||||
|
@ -429,30 +454,22 @@ function parseArtistOrLabelInfo(html, opts) {
|
||||||
description = '';
|
description = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
let isLabel = $('a[href="/artists"]').length;
|
let isLabel = bandData.is_label;
|
||||||
let label = null;
|
|
||||||
if (!isLabel) {
|
|
||||||
let labelLink = $('a.back-to-label-link');
|
|
||||||
if (labelLink.length) {
|
|
||||||
let linkText = labelLink.find('.back-link-text').html();
|
|
||||||
label = {
|
|
||||||
name: utils.substrAfter(linkText, '<br>') || utils.substrBefore(linkText, ' に戻る') || utils.substrBefore(linkText, ' のアイテムをもっと聴く'),
|
|
||||||
url: utils.splitUrl(labelLink.attr('href')).base
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
type: isLabel ? 'label' : 'artist',
|
type: isLabel ? 'label' : 'artist',
|
||||||
name: $('#band-name-location').find('.title').text(),
|
name: bandData.name,
|
||||||
url: opts.artistOrLabelUrl,
|
url: bandData.url,
|
||||||
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) {
|
||||||
result.label = label;
|
result.label = _parseBackToLabelLink($);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
result.labelId = bandData.id;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1047,7 +1064,7 @@ function parseHubJSPath(html) {
|
||||||
|
|
||||||
function parseHubJSFilterValueNames(js) {
|
function parseHubJSFilterValueNames(js) {
|
||||||
const filterValueNames = {};
|
const filterValueNames = {};
|
||||||
const tObj = /"hubs\/digdeeper\/filter_value":(.+?)}\);/gs.exec(js);
|
const tObj = /"hubs\/digdeeper\/filter_value":(.+?)}\),/gs.exec(js);
|
||||||
if (tObj[1]) {
|
if (tObj[1]) {
|
||||||
const t = safeEval(tObj[1]);
|
const t = safeEval(tObj[1]);
|
||||||
if (t && t[0] && Array.isArray(t[0].blocks)) {
|
if (t && t[0] && Array.isArray(t[0].blocks)) {
|
||||||
|
@ -1237,6 +1254,47 @@ function parseSearchLocationResults(json) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _parseBackToLabelLink($) {
|
||||||
|
let labelLink = $('.back-to-label-link');
|
||||||
|
if (labelLink.length) {
|
||||||
|
let linkText = labelLink.find('.back-link-text').html();
|
||||||
|
label = {
|
||||||
|
name: utils.substrAfter(linkText, '<br/>') ||
|
||||||
|
utils.substrAfter(linkText, '<br>') ||
|
||||||
|
utils.substrBefore(linkText, ' に戻る') ||
|
||||||
|
utils.substrBefore(linkText, ' のアイテムをもっと聴く'),
|
||||||
|
url: utils.splitUrl(labelLink.attr('href')).base
|
||||||
|
};
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _setPublisher(target, json, imageFormat) {
|
||||||
|
if (json.publisher) {
|
||||||
|
let publisher = {
|
||||||
|
name: json.publisher.name,
|
||||||
|
url: json.publisher['@id'],
|
||||||
|
description: json.publisher.description,
|
||||||
|
imageUrl: utils.reformatImageUrl(json.publisher.image, imageFormat)
|
||||||
|
}
|
||||||
|
target.publisher = publisher;
|
||||||
|
|
||||||
|
// For backward compatibility
|
||||||
|
if (target.artist) {
|
||||||
|
if (target.artist.url === null) {
|
||||||
|
target.artist.url = target.publisher.url;
|
||||||
|
}
|
||||||
|
target.artist.description = target.publisher.description;
|
||||||
|
target.artist.imageUrl = target.publisher.imageUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
target.publisher = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
parseDiscoverResults,
|
parseDiscoverResults,
|
||||||
parseDiscoverOptions,
|
parseDiscoverOptions,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user