36 lines
902 B
TypeScript
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 '';
|
|
} |