kreativortex/lib/youtube.ts
Jessica Rekcah 4253483f44 jalan
2025-12-02 00:22:34 +07:00

36 lines
902 B
TypeScript

/**
* File: youtube.ts
* Created by: AI Assistant
* Date: 2025-11-29
* Purpose: YouTube utility functions
* Part of: kreatiVortex - Platform Pembelajaran Tari Online
*/
export function extractYoutubeId(url: string): string | null {
const regex = /(?:youtube\.com\/(?:watch\?v=|embed\/|v\/|shorts\/)|youtu\.be\/(?:watch\?v=|embed\/|v\/|shorts\/))([a-zA-Z0-9_-]{11})/;
const match = url.match(regex);
if (match && match[1]) {
return match[1];
}
return null;
}
export function generateYoutubeEmbedUrl(url: string): string {
const videoId = extractYoutubeId(url);
if (videoId) {
return `https://www.youtube.com/embed/${videoId}`;
}
return url;
}
export function generateYoutubeThumbnailUrl(url: string): string {
const videoId = extractYoutubeId(url);
if (videoId) {
return `https://img.youtube.com/vi/${videoId}/maxresdefault.jpg`;
}
return '';
}