UNPKG

social-link-parser

Version:

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

49 lines 1.7 kB
import { Platforms } from '../../core/types.js'; import { normalize } from '../../utils/url.js'; import { QUERY_HASH } from '../../utils/constants.js'; const domains = ['dailymotion.com', 'dai.ly']; const subdomains = []; export const dailymotion = { id: Platforms.Dailymotion, name: 'Dailymotion', color: '#0066DC', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://(?:www\\.)?dailymotion\\.com/(?!video(?:/|$))([A-Za-z0-9_-]{3,30})/?${QUERY_HASH}$`, 'i'), handle: /^[A-Za-z0-9_-]{3,30}$/, content: { video: new RegExp(`^https?://(?:(?:www\\.)?dailymotion\\.com/video|dai\\.ly)/([A-Za-z0-9]{6,10})/?${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)); }, extract(url, res) { const vid = this.patterns.content?.video?.exec(url); if (vid) { res.ids.videoId = vid[1]; res.metadata.isVideo = true; res.metadata.contentType = 'video'; return; } const prof = this.patterns.profile.exec(url); if (prof) { res.username = prof[1]; res.metadata.isProfile = true; res.metadata.contentType = 'profile'; } }, validateHandle(handle) { return this.patterns.handle.test(handle); }, buildProfileUrl(handle) { return `https://www.dailymotion.com/${handle}`; }, normalizeUrl(url) { return normalize(url); }, }; //# sourceMappingURL=index.js.map