UNPKG

@rolme/ytscript

Version:

A CLI tool to download YouTube transcripts and generate summaries

27 lines (26 loc) 673 B
import { TranscriptError } from '../errors.js'; export function getVideoId(url) { try { const urlObj = new URL(url); const videoId = urlObj.searchParams.get('v'); if (!videoId) { throw new TranscriptError('Invalid YouTube URL: Missing video ID'); } return videoId; } catch (error) { if (error instanceof TranscriptError) { throw error; } throw new TranscriptError('Invalid YouTube URL'); } } export function validateUrl(url) { try { const videoId = getVideoId(url); return videoId.length > 0; } catch (error) { return false; } }