UNPKG

yt-dlx

Version:

Effortless Audio-Video Downloader And Streamer!

27 lines 1.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = YouTubeID; async function YouTubeID(videoLink) { const patterns = [/youtu\.be\/([^#&?]{11})/, /\?v=([^#&?]{11})/, /&v=([^#&?]{11})/, /embed\/([^#&?]{11})/, /\/v\/([^#&?]{11})/, /list=([^#&?]+)/, /playlist\?list=([^#&?]+)/]; for (const pattern of patterns) { const match = pattern.exec(videoLink); if (match) { if (pattern === patterns[patterns.length - 1]) { try { const urlParams = new URLSearchParams(match[0]); const videoId = urlParams.get("v"); return videoId || undefined; } catch (error) { console.error("Error parsing URL:", error); return undefined; } } else { return match[1]; } } } return undefined; } //# sourceMappingURL=YouTubeId.js.map