UNPKG

bandcamp-fetch

Version:
65 lines 2.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const cheerio_1 = require("cheerio"); const html_entities_1 = require("html-entities"); const Parse_js_1 = require("../utils/Parse.js"); class BandInfoParser { static parseInfo(html, opts) { const $ = (0, cheerio_1.load)(html); let bandData; try { bandData = JSON.parse((0, html_entities_1.decode)($('script[data-band]').attr('data-band'))); } catch (error) { throw new Parse_js_1.ParseError('Failed to parse artist / label info: JSON error in band data.', html, error); } const bioText = $('#bio-text'); let description; if (bioText.length) { const bioTextMore = bioText.find('.peekaboo-text'); if (bioTextMore.length) { bioTextMore.find('.lightweightBreak').remove(); bioText.find('.peekaboo-text, .peekaboo-link').remove(); description = `${bioText.html()?.trim()} ${bioTextMore.html()}`.trim(); } else { description = bioText.html()?.trim(); } if (description) { description = (0, Parse_js_1.stripLineBreaks)(description); description = (0, Parse_js_1.brToNewLine)(description); description = (0, Parse_js_1.stripTags)(description); description = (0, html_entities_1.decode)(description); } } const isLabel = bandData.is_label; const result = { type: isLabel ? 'label' : 'artist', name: bandData.name, description: description }; if (bandData.url) { result.url = bandData.url; } const location = $('#band-name-location').find('.location').text(); if (location) { result.location = location; } const imageUrl = (0, Parse_js_1.reformatImageUrl)($('img.band-photo').attr('src'), opts.imageFormat); if (imageUrl) { result.imageUrl = imageUrl; } if (!isLabel) { const label = (0, Parse_js_1.parseLabelFromBackToLabelLink)($); if (label) { result.label = label; } } else { result.labelId = bandData.id; } return result; } } exports.default = BandInfoParser; //# sourceMappingURL=BandInfoParser.js.map