UNPKG

social-link-parser

Version:

Extract usernames, IDs, and metadata from social media URLs across 100+ platforms

60 lines 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pandora = void 0; const types_1 = require("../../core/types"); const url_1 = require("../../utils/url"); const url_2 = require("../../utils/url"); const constants_1 = require("../../utils/constants"); const domains = ['pandora.com']; const subdomains = []; const DOMAIN_PATTERN = (0, url_2.createDomainPattern)(domains, subdomains); exports.pandora = { id: types_1.Platforms.Pandora, name: 'Pandora', color: '#005483', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://${DOMAIN_PATTERN}/(artist|podcast)/([A-Za-z0-9_-]{3,100})(?:/.*)?${constants_1.QUERY_HASH}$`, 'i'), handle: /^[A-Za-z0-9_-]{3,100}$/, content: { station: new RegExp(`^https?://${DOMAIN_PATTERN}/station/play/(\\d+)${constants_1.QUERY_HASH}`, 'i'), }, }, detect(url) { if (!this.domains.some(domain => url.includes(domain))) return false; return this.patterns.profile.test(url) || !!(this.patterns.content?.station?.test(url)); }, extract(url, res) { const station = this.patterns.content?.station?.exec(url); if (station) { res.ids.stationId = station[1]; res.metadata.isStation = true; res.metadata.contentType = 'station'; return; } const prof = this.patterns.profile.exec(url); if (prof) { res.username = prof[2]; if (prof[1] === 'artist') { res.metadata.isArtist = true; res.metadata.contentType = 'artist'; } else if (prof[1] === 'podcast') { res.metadata.isPodcast = true; res.metadata.contentType = 'podcast'; } } }, validateHandle(handle) { return this.patterns.handle.test(handle); }, buildProfileUrl(username) { return `https://pandora.com/artist/${username}`; }, normalizeUrl(url) { return (0, url_1.normalize)(url); }, }; //# sourceMappingURL=index.js.map