YT Fixes
This commit is contained in:
@@ -21,8 +21,9 @@ const YOUTUBE_URL_PATTERNS = [
|
||||
|
||||
/**
|
||||
* YouTube embed URL base - fallback when yt-dlp is not available
|
||||
* Using youtube-nocookie.com to avoid Error 153 and embedding restrictions
|
||||
*/
|
||||
const YOUTUBE_EMBED_BASE = 'https://www.youtube.com/embed';
|
||||
const YOUTUBE_EMBED_BASE = 'https://www.youtube-nocookie.com/embed';
|
||||
|
||||
/**
|
||||
* YouTube oEmbed API base - used to fetch video metadata
|
||||
@@ -88,10 +89,15 @@ export function extractYouTubeVideoId(url: string): string | null {
|
||||
/**
|
||||
* Generates a YouTube embed URL for a video (fallback)
|
||||
* @param videoId The YouTube video ID
|
||||
* @returns The embed URL
|
||||
* @returns The embed URL with parameters to avoid Error 153
|
||||
*/
|
||||
export function getYouTubeEmbedUrl(videoId: string): string {
|
||||
return `${YOUTUBE_EMBED_BASE}/${videoId}?autoplay=1`;
|
||||
// Use youtube-nocookie.com and add parameters to help with embedding
|
||||
// autoplay=1 - start playing when loaded
|
||||
// rel=0 - only show related videos from same channel
|
||||
// modestbranding=1 - minimize YouTube branding
|
||||
// enablejsapi=1 - enable JavaScript API for better compatibility
|
||||
return `${YOUTUBE_EMBED_BASE}/${videoId}?autoplay=1&rel=0&modestbranding=1&enablejsapi=1`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -255,8 +261,9 @@ export const YouTubeEmbed = as<'div', YouTubeEmbedProps>(({ url, ...props }, ref
|
||||
className={css.YouTubeEmbedIframe}
|
||||
src={embedUrl}
|
||||
title="YouTube video player"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
||||
allowFullScreen
|
||||
referrerPolicy="strict-origin-when-cross-origin"
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user