UNPKG

social-link-parser

Version:

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

67 lines 2.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.peertube = void 0; const types_1 = require("../../core/types"); const url_1 = require("../../utils/url"); const constants_1 = require("../../utils/constants"); const handlePattern = /^[A-Za-z0-9_-]{3,40}$/; const profileA = new RegExp(`^https?://([A-Za-z0-9.-]+)/a/([A-Za-z0-9_-]{3,40})/?${constants_1.QUERY_HASH}$`, 'i'); const profileChannel = new RegExp(`^https?://([A-Za-z0-9.-]+)/video-channels/([A-Za-z0-9_-]{3,40})/?${constants_1.QUERY_HASH}$`, 'i'); const videoWatch = new RegExp(`^https?://([A-Za-z0-9.-]+)/videos/watch/([A-Za-z0-9_-]{8,})/?${constants_1.QUERY_HASH}$`, 'i'); const videoEmbed = new RegExp(`^https?://([A-Za-z0-9.-]+)/videos/embed/([A-Za-z0-9_-]{8,})/?${constants_1.QUERY_HASH}$`, 'i'); exports.peertube = { id: types_1.Platforms.PeerTube, name: 'PeerTube', color: '#F1680D', domains: [], patterns: { profile: profileA, handle: handlePattern, content: { videoWatch, videoEmbed, }, }, detect(url) { if (!/\/videos\//i.test(url) && !/\/a\//i.test(url) && !/\/video-channels\//i.test(url)) return false; return profileA.test(url) || profileChannel.test(url) || videoWatch.test(url) || videoEmbed.test(url); }, extract(url, result) { const v = videoWatch.exec(url) || videoEmbed.exec(url); if (v) { result.ids.videoId = v[2]; result.metadata.isVideo = true; result.metadata.contentType = 'video'; return; } const pA = profileA.exec(url); if (pA) { result.username = pA[2]; result.metadata.isProfile = true; result.metadata.contentType = 'profile'; return; } const pC = profileChannel.exec(url); if (pC) { result.username = pC[2]; result.metadata.isProfile = true; result.metadata.contentType = 'profile'; } }, validateHandle(handle) { return handlePattern.test(handle); }, buildProfileUrl(username) { return `https://peertube.social/a/${username}`; }, buildContentUrl(type, id) { if (type === 'video') return `https://peertube.social/videos/watch/${id}`; return `https://peertube.social/${id}`; }, normalizeUrl(url) { return (0, url_1.normalize)(url); }, }; //# sourceMappingURL=index.js.map