UNPKG

social-link-parser

Version:

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

62 lines 2.29 kB
import { Platforms } from '../../core/types.js'; import { normalize } from '../../utils/url.js'; import { createDomainPattern } from '../../utils/url.js'; import { QUERY_HASH } from '../../utils/constants.js'; const domains = ['vimeo.com']; const subdomains = []; const DOMAIN_PATTERN = createDomainPattern(domains, subdomains); export const vimeo = { id: Platforms.Vimeo, name: 'Vimeo', color: '#1AB7EA', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://${DOMAIN_PATTERN}/(?:user\\d+|[A-Za-z0-9_]{3,32})/?${QUERY_HASH}$`, 'i'), handle: /^(?:user\d+|[A-Za-z0-9_]{3,32})$/, content: { video: new RegExp(`^https?://${DOMAIN_PATTERN}/(\\d{6,12})/?${QUERY_HASH}$`, 'i'), channel: new RegExp(`^https?://${DOMAIN_PATTERN}/channels/([A-Za-z0-9_-]{3,32})/?${QUERY_HASH}$`, 'i'), }, }, detect(url) { if (!this.domains.some(domain => url.includes(domain))) return false; return this.patterns.profile.test(url) || !!(this.patterns.content?.video?.test(url)) || !!(this.patterns.content?.channel?.test(url)); }, extract(url, res) { const videoMatch = this.patterns.content?.video?.exec(url); if (videoMatch) { res.ids.videoId = videoMatch[1]; res.metadata.isVideo = true; res.metadata.contentType = 'video'; return; } const channelMatch = this.patterns.content?.channel?.exec(url); if (channelMatch) { res.username = channelMatch[1]; res.metadata.isChannel = true; res.metadata.contentType = 'channel'; return; } const profMatch = this.patterns.profile.exec(url); if (profMatch) { const path = url.split('/').pop()?.split('?')[0] || ''; res.username = path; res.metadata.isProfile = true; res.metadata.contentType = 'profile'; } }, validateHandle(handle) { return this.patterns.handle.test(handle); }, buildProfileUrl(username) { return `https://vimeo.com/${username}`; }, normalizeUrl(url) { return normalize(url); }, }; //# sourceMappingURL=index.js.map