opex-yt-id
Version:
Extracts YouTube video, channel, and playlist IDs from various URLs
38 lines (33 loc) • 1.93 kB
TypeScript
// index.d.ts
/**
* Attempts to extract the YouTube Video ID from a wide variety of URL formats.
* Covers official (standard, mobile, music, kids, nocookie, regional),
* shorteners, embed, image links, attribution links,
* mobile schemes, common third-party frontends (static examples), iframes,
* and some legacy/rare patterns. Includes a generic fallback for '/watch?v='.
*
* @param urlString The URL or string potentially containing a YouTube video link or ID.
* @returns The 11-character YouTube Video ID, or null if not found or invalid.
*/
export declare function getYouTubeVideoId(urlString: string | null | undefined): string | null;
/**
* Attempts to extract the YouTube Channel ID (starting with 'UC') from URL formats.
* Primarily looks for '/channel/UC...' patterns on YouTube and known third-party domains.
*
* **Important:** This function does *not* resolve custom channel URLs (e.g., `/c/ChannelName`),
* legacy usernames (e.g., `/user/UserName`), or handles (e.g., `/@Handle`). Resolving these
* requires API calls or scraping and is outside the scope of simple URL parsing.
*
* @param urlString The URL or string potentially containing a YouTube channel link.
* @returns The 24-character YouTube Channel ID (starting with 'UC'), or null if not found or invalid.
*/
export declare function getYouTubeChannelId(urlString: string | null | undefined): string | null;
/**
* Attempts to extract the YouTube Playlist ID (starting with 'PL') from URL formats.
* Primarily looks for the `list=PL...` query parameter on YouTube, Music, known third-party domains.
* Focuses on standard shareable playlist IDs.
*
* @param urlString The URL or string potentially containing a YouTube playlist link.
* @returns The YouTube Playlist ID (starting with 'PL'), or null if not found or invalid.
*/
export declare function getYouTubePlaylistId(urlString: string | null | undefined): string | null;