Chandima Prabhath commited on
Commit ·
beeb302
1
Parent(s): 29f13f9
update
Browse filesFiles changed (7)
123456[build]command = "npm run build"publish = "dist"
[dev]command = "npm run dev"291 unmodified lines29229329429529629729829930030130227 unmodified lines33033133233333433533618 unmodified lines355356357358359360361362363291 unmodified linesreturn (<divclassName="relative flex-shrink-0 w-[240px] md:w-[280px] card-hover group"onMouseEnter={() => setIsHovered(true)}onMouseLeave={() => setIsHovered(false)}><div className="relative rounded-md overflow-hidden shadow-xl bg-theme-card h-[140px] md:h-[160px]">{/* Base card image */}<Link to={path} className="block h-full">{loading ? (27 unmodified lines{/* Title overlay (simple version when not hovered) */}<div className={`absolute inset-x-0 bottom-0 p-3 ${isHovered ? 'opacity-0' : 'opacity-100'}transition-opacity duration-300 bg-gradient-to-t from-black/90 to-transparent`}><div className="flex items-center"><h3 className="font-bold text-sm line-clamp-1 flex-1">{title}</h3>{progress?.completed && (18 unmodified lines{/* Expanded hover overlay with detailed info and buttons */}<divclassName={`fixed group-hover:absolute inset-0 z-20 bg-gradient-to-b from-black/90 to-theme-background-darktransition-opacity duration-300 flex flex-col justify-between p-3 w-[240px] md:w-[280px] h-[140px] md:h-[160px]${isHovered ? 'opacity-100' : 'opacity-0 pointer-events-none'}`}>{/* Top section - title and info */}<div>291 unmodified lines29229329429529629729829930030130227 unmodified lines33033133233333433533618 unmodified lines355356357358359360361362363291 unmodified linesreturn (<divclassName="relative flex-shrink-0 w-[240px] md:w-[280px] h-full card-hover group"onMouseEnter={() => setIsHovered(true)}onMouseLeave={() => setIsHovered(false)}><div className="relative rounded-md overflow-hidden shadow-xl bg-theme-card h-[170px] md:h-[170px]">{/* Base card image */}<Link to={path} className="block h-full">{loading ? (27 unmodified lines{/* Title overlay (simple version when not hovered) */}<div className={`absolute inset-x-0 bottom-0 p-3 ${isHovered ? 'opacity-0' : 'opacity-100'}transition-opacity duration-300 bg-gradient-to-t from-black to-transparent`}><div className="flex items-center"><h3 className="font-bold text-sm line-clamp-1 flex-1">{title}</h3>{progress?.completed && (18 unmodified lines{/* Expanded hover overlay with detailed info and buttons */}<divclassName={`fixed group-hover:absolute inset-0 z-20 bg-gradient-to-b from-black/40 to-theme-background-darktransition-all duration-300 flex flex-col justify-between p-3 w-full h-full${isHovered ? 'opacity-100 backdrop-blur-md' : 'opacity-0 pointer-events-none backdrop-blur-none'}`}>{/* Top section - title and info */}<div>
87 unmodified lines888990919293949542 unmodified lines13813914014114214314416 unmodified lines16116216316416516616787 unmodified linestarget.src = '/placeholder.svg';}}/><div className="absolute inset-0 bg-gradient-to-t from-black via-black/60 to-transparent" /><div className="absolute inset-0 bg-gradient-to-r from-black/80 via-black/40 to-transparent" /></motion.div></AnimatePresence>42 unmodified lines<div className="flex space-x-3"><Linkto={`${path}/watch`}className="flex items-center px-6 py-2 rounded bg-indigo-600 text-white font-semibold hover:bg-indigo-700 transition"><Play className="w-5 h-5 mr-2" /> Play</Link>16 unmodified linesonClick={() => handleDotClick(index)}className={`w-2.5 h-2.5 rounded-full transition-all ${index === currentIndex? 'bg-indigo-500 w-6': 'bg-gray-500/50 hover:bg-gray-400/70'}`}aria-label={`Go to slide ${index + 1}`}87 unmodified lines888990919293949542 unmodified lines13813914014114214314416 unmodified lines16116216316416516616787 unmodified linestarget.src = '/placeholder.svg';}}/><div className="absolute inset-0 bg-gradient-to-t from-netflix-black via-netflix-black/60 to-transparent" /><div className="absolute inset-0 bg-gradient-to-r from-netflix-black/80 via-netflix-black/40 to-transparent" /></motion.div></AnimatePresence>42 unmodified lines<div className="flex space-x-3"><Linkto={`${path}/watch`}className="flex items-center px-6 py-2 rounded bg-theme-primary text-white font-semibold hover:bg-theme-primary-hover transition"><Play className="w-5 h-5 mr-2" /> Play</Link>16 unmodified linesonClick={() => handleDotClick(index)}className={`w-2.5 h-2.5 rounded-full transition-all ${index === currentIndex? 'bg-theme-primary-light w-5': 'bg-gray-500/50 hover:bg-gray-400/70'}`}aria-label={`Go to slide ${index + 1}`}
3 unmodified lines4567896 unmodified lines161718192021226 unmodified lines293031323334356 unmodified lines42434445464748495051525354555657585960616263641 unmodified line6667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319410 unmodified lines2052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652663 unmodified lines2702712722732742752762773 unmodified linesimport VideoPlayer from './VideoPlayer';import VideoPlayerControls from './VideoPlayerControls';import { Loader2, Play } from 'lucide-react';interface ProgressData {status: string;6 unmodified linesmovieTitle: string;videoUrl?: string;contentRatings?: any[];thumbnail?: string;poster?: string;startTime?: number;onClosePlayer?: () => void;6 unmodified linesmovieTitle,videoUrl,contentRatings,thumbnail,poster,startTime = 0,onClosePlayer,6 unmodified linesconst [error, setError] = useState<string | null>(null);const [progress, setProgress] = useState<ProgressData | null>(null);const [videoFetched, setVideoFetched] = useState(!!videoUrl);const { toast } = useToast();const pollingIntervalRef = useRef<NodeJS.Timeout | null>(null);const timeoutRef = useRef<NodeJS.Timeout | null>(null);const videoFetchedRef = useRef(!!videoUrl);const [ratingInfo, setRatingInfo] = useState<{ rating: string, description: string } | null>(null);const [currentTime, setCurrentTime] = useState(startTime);const containerRef = useRef<HTMLDivElement>(null);const videoRef = useRef<HTMLVideoElement>(null);// Update the onProgressUpdate handler to also update currentTimeconst handleProgressUpdate = (time: number, duration: number) => {setCurrentTime(time);onProgressUpdate?.(time, duration);};// Handler for seeking from WatchTogetherconst handleSeek = (time: number) => {if (videoRef.current) {videoRef.current.currentTime = time;1 unmodified line}};// --- Link Fetching & Polling ---const fetchMovieLink = async () => {if (videoFetchedRef.current || videoUrlState) return;try {const response = await getMovieLinkByTitle(movieTitle);if (response && response.url) {// Stop any polling if runningif (pollingIntervalRef.current) {clearInterval(pollingIntervalRef.current);pollingIntervalRef.current = null;}setVideoUrlState(response.url);setVideoFetched(true);videoFetchedRef.current = true;setLoading(false); // Ensure loading is set to false when URL is fetchedconsole.log('Video URL fetched:', response.url);} else if (response && response.progress_url) {startPolling(response.progress_url);} else {console.error('No video URL or progress URL found in response:', response);setError('Video URL not available');}} catch (error) {console.error('Error fetching movie link:', error);setError('Failed to load video');toast({title: "Error",description: "Could not load the video",variant: "destructive"});} finally {// Only set loading to false if we don't have a video yetif (!videoFetchedRef.current && !videoUrlState) {setLoading(false);}}};// Fetch content ratings if not provideduseEffect(() => {const fetchRatingInfo = async () => {if (contentRatings && contentRatings.length > 0) {const usRating = contentRatings.find(r => r.country === 'usa') || contentRatings[0];setRatingInfo({rating: usRating.name || 'NR',description: usRating.description || ''});return;}try {const movieData = await getMovieCard(movieTitle);if (movieData && movieData.content_ratings) {const ratings = movieData.content_ratings;const usRating = ratings.find((r: any) => r.country === 'US') || ratings[0];setRatingInfo({rating: usRating?.name || 'NR',description: usRating?.description || ''});}} catch (error) {console.error('Failed to fetch movie ratings:', error);}};fetchRatingInfo();}, [movieTitle, contentRatings]);const pollProgress = async (progressUrl: string) => {try {const res = await fetch(progressUrl);const data = await res.json();setProgress(data.progress);if (data.progress.progress >= 100) {if (pollingIntervalRef.current) {clearInterval(pollingIntervalRef.current);pollingIntervalRef.current = null;}if (!videoFetchedRef.current) {timeoutRef.current = setTimeout(fetchMovieLink, 5000);}}} catch (error) {console.error('Error polling progress:', error);}};const startPolling = (progressUrl: string) => {if (!pollingIntervalRef.current) {const interval = setInterval(() => pollProgress(progressUrl), 2000);pollingIntervalRef.current = interval;}};// Cleanup on unmount and when dependencies changeuseEffect(() => {if (!videoUrlState) {fetchMovieLink();} else {setVideoFetched(true);videoFetchedRef.current = true;setLoading(false); // Make sure loading is false when we have a URL}return () => {if (pollingIntervalRef.current) clearInterval(pollingIntervalRef.current);if (timeoutRef.current) clearTimeout(timeoutRef.current);};}, [movieTitle, videoUrl]);// Add effect to update loading state when videoUrlState changesuseEffect(() => {if (videoUrlState) {setLoading(false);}}, [videoUrlState]);if (error) {return (<div className="fixed inset-0 z-50 bg-black flex flex-col items-center justify-center">10 unmodified lines);}if (loading || !videoFetched || !videoUrlState) {return (<div className="fixed inset-0 z-50 bg-gradient-to-br from-theme-background-dark to-black flex flex-col items-center justify-center"><div className="text-center max-w-md px-6"><div className="mb-6 flex justify-center">{poster ? (<img src={poster} alt={movieTitle} className="h-auto w-24 rounded-lg shadow-lg" />) : (<div className="flex items-center justify-center h-24 w-24 bg-theme-primary/20 rounded-lg"><Play className="h-12 w-12 text-theme-primary" /></div>)}</div><h2 className="text-2xl md:text-3xl font-bold text-white mb-4">{progress && progress.progress < 100? `Preparing "${movieTitle}"`: `Loading "${movieTitle}"`}</h2>{progress ? (<><p className="text-gray-300 mb-4">{progress.progress < 5? 'Initializing your stream...': progress.progress < 100? 'Your stream is being prepared.': 'Almost ready! Starting playback soon...'}</p><div className="relative w-full h-2 bg-gray-800 rounded-full overflow-hidden mb-2"><divclassName="absolute top-0 left-0 h-full bg-gradient-to-r from-theme-primary to-theme-primary-light transition-all duration-300"style={{ width: `${Math.min(100, Math.max(0, progress.progress))}%` }}/></div><p className="text-sm text-gray-400">{Math.round(progress.progress)}% complete</p></>) : (<div className="flex justify-center"><Loader2 className="h-8 w-8 animate-spin text-theme-primary" /></div>)}</div></div>);}return (<div ref={containerRef} className="fixed inset-0 h-screen w-screen overflow-hidden"><VideoPlayerurl={videoUrlState}title={movieTitle}poster={poster || thumbnail}startTime={startTime}onClose={onClosePlayer}onProgressUpdate={handleProgressUpdate}3 unmodified linescontainerRef={containerRef}videoRef={videoRef}/><VideoPlayerControlstitle={movieTitle}currentTime={currentTime}duration={videoRef.current?.duration || 0}3 unmodified lines456789106 unmodified lines1718192021226 unmodified lines2930313233346 unmodified lines414243444546474849505152535455565758596061626364656667686970711 unmodified line73747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617710 unmodified lines1881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662673 unmodified lines2712722732742752762773 unmodified linesimport VideoPlayer from './VideoPlayer';import VideoPlayerControls from './VideoPlayerControls';import { Loader2, Play } from 'lucide-react';import { MovieCardData } from './ContentCard';interface ProgressData {status: string;6 unmodified linesmovieTitle: string;videoUrl?: string;contentRatings?: any[];poster?: string;startTime?: number;onClosePlayer?: () => void;6 unmodified linesmovieTitle,videoUrl,contentRatings,poster,startTime = 0,onClosePlayer,6 unmodified linesconst [error, setError] = useState<string | null>(null);const [progress, setProgress] = useState<ProgressData | null>(null);const [videoFetched, setVideoFetched] = useState(!!videoUrl);const [cardData, setCardData] = useState<MovieCardData | null>(null);const [selectedImage, setSelectedImage] = useState<string | null>(null);const [imageLoaded, setImageLoaded] = useState(false);const { toast } = useToast();const pollingIntervalRef = useRef<NodeJS.Timeout | null>(null);const timeoutRef = useRef<NodeJS.Timeout | null>(null);const videoFetchedRef = useRef(!!videoUrl);const [ratingInfo, setRatingInfo] = useState<{ rating: string; description: string } | null>(null);const [currentTime, setCurrentTime] = useState(startTime);const containerRef = useRef<HTMLDivElement>(null);const videoRef = useRef<HTMLVideoElement>(null);// Reset fade state when image changesuseEffect(() => {setImageLoaded(false);}, [selectedImage]);// Update progress and propagate upconst handleProgressUpdate = (time: number, duration: number) => {setCurrentTime(time);onProgressUpdate?.(time, duration);};// Seek handlerconst handleSeek = (time: number) => {if (videoRef.current) {videoRef.current.currentTime = time;1 unmodified line}};// Random image selectorconst selectRandomImage = (card: MovieCardData | null) => {if (!card) return null;if (card.banner && card.banner.length > 0) {return card.banner[Math.floor(Math.random() * card.banner.length)].image;}if (card.portrait && card.portrait.length > 0) {return card.portrait[Math.floor(Math.random() * card.portrait.length)].image;}return card.image;};// Fetch movie link or start pollingconst fetchMovieLink = async () => {if (videoFetchedRef.current || videoUrlState) return;try {const response = await getMovieLinkByTitle(movieTitle);if (response.url) {pollingIntervalRef.current && clearInterval(pollingIntervalRef.current);setVideoUrlState(response.url);setVideoFetched(true);videoFetchedRef.current = true;setLoading(false);} else if (response.progress_url) {if (!pollingIntervalRef.current) {pollingIntervalRef.current = setInterval(async () => {try {const res = await fetch(response.progress_url!);const data = await res.json();setProgress(data.progress);if (data.progress.progress >= 100) {clearInterval(pollingIntervalRef.current!);timeoutRef.current = setTimeout(fetchMovieLink, 5000);}} catch (e) {console.error(e);}}, 2000);}} else {throw new Error('No URL or progress URL');}} catch (e) {console.error('Error fetching movie link:', e);setError('Failed to load video');toast({ title: 'Error', description: 'Could not load the video', variant: 'destructive' });setLoading(false);}};// Fetch card data & ratingsuseEffect(() => {const fetchCard = async () => {try {const movieData = await getMovieCard(movieTitle);setCardData(movieData);const img = selectRandomImage(movieData);setSelectedImage(img);// Poster fallbackif (!poster) {poster = movieData.image || poster;}// Ratingsconst ratings = contentRatings && contentRatings.length > 0? contentRatings: movieData.content_ratings || [];if (ratings.length) {const us = ratings.find((r: any) => r.country === 'usa') || ratings[0];setRatingInfo({ rating: us.name || 'NR', description: us.description || '' });}} catch (e) {console.error('Failed to fetch movie card:', e);}};fetchCard();}, [movieTitle, contentRatings, poster]);// Initial link fetch / cleanupuseEffect(() => {if (!videoUrlState) {fetchMovieLink();} else {setVideoFetched(true);videoFetchedRef.current = true;setLoading(false);}return () => {pollingIntervalRef.current && clearInterval(pollingIntervalRef.current);timeoutRef.current && clearTimeout(timeoutRef.current);};}, [movieTitle, videoUrlState]);// Sync loading stateuseEffect(() => {if (videoUrlState) setLoading(false);}, [videoUrlState]);// Error UIif (error) {return (<div className="fixed inset-0 z-50 bg-black flex flex-col items-center justify-center">10 unmodified lines);}// Loading / preparing UI with fade‑in backdropif (loading || !videoFetched || !videoUrlState) {return (<><div className="relative w-full h-full"><div className="absolute inset-0"><imgsrc={selectedImage}onLoad={() => setImageLoaded(true)}onError={(e) => {(e.target as HTMLImageElement).src = '/placeholder.svg';}}className={`w-full h-full object-cover transition-opacity duration-700 ease-in-out ${imageLoaded ? 'opacity-100' : 'opacity-0'}`}/><div className="absolute inset-0 bg-gradient-to-t from-netflix-black via-netflix-black/50 to-transparent" /><div className="absolute inset-0 bg-gradient-to-r from-netflix-black/80 via-netflix-black/40 to-transparent" /></div></div><div className="fixed inset-0 z-50 flex flex-col items-center backdrop-blur-sm justify-center"><div className="text-center max-w-md px-6"><div className="mb-6 flex justify-center">{poster ? (<img src={poster} alt={movieTitle} className="h-auto w-24 rounded-lg shadow-lg" />) : (<div className="flex items-center justify-center h-24 w-24 bg-theme-primary/20 rounded-lg"><Play className="h-12 w-12 text-theme-primary" /></div>)}</div><h2 className="text-2xl md:text-3xl font-bold text-white mb-4">{progress && progress.progress < 100? `Preparing "${movieTitle}"`: `Loading "${movieTitle}"`}</h2>{progress ? (<><p className="text-gray-300 mb-4">{progress.progress < 5? 'Initializing your stream...': progress.progress < 100? 'Your stream is being prepared.': 'Almost ready! Starting playback soon...'}</p><div className="relative w-full h-2 bg-gray-800 rounded-full overflow-hidden mb-2"><divclassName="absolute top-0 left-0 h-full bg-gradient-to-r from-theme-primary to-theme-primary-light transition-all duration-300"style={{ width: `${Math.min(100, Math.max(0, progress.progress))}%` }}/></div><p className="text-sm text-gray-400">{Math.round(progress.progress)}% complete</p></>) : (<div className="flex justify-center"><Loader2 className="h-8 w-8 animate-spin text-theme-primary" /></div>)}</div></div></>);}// Playback UIreturn (<div ref={containerRef} className="fixed inset-0 h-screen w-screen overflow-hidden"><VideoPlayerurl={videoUrlState}title={movieTitle}poster={selectedImage || undefined}startTime={startTime}onClose={onClosePlayer}onProgressUpdate={handleProgressUpdate}3 unmodified linescontainerRef={containerRef}videoRef={videoRef}/><VideoPlayerControlstitle={movieTitle}currentTime={currentTime}duration={videoRef.current?.duration || 0}
2 unmodified lines34567814 unmodified lines232425262728298 unmodified lines383940414243446 unmodified lines515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062074 unmodified lines2122132142152162172183 unmodified lines2222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782799 unmodified lines28929029129229329429529611 unmodified lines3083093103113123133142 unmodified linesimport { useToast } from '@/hooks/use-toast';import { Film, GalleryVerticalEnd, Loader2, Play } from 'lucide-react';import VideoPlayer from './VideoPlayer';interface ProgressData {status: string;14 unmodified linesepisode: string;movieTitle: string;contentRatings?: ContentRating[];thumbnail?: string;poster?: string;startTime?: number;onClosePlayer?: () => void;8 unmodified linesepisode,movieTitle,contentRatings,thumbnail,poster,startTime = 0,onClosePlayer,6 unmodified linesconst [error, setError] = useState<string | null>(null);const [progress, setProgress] = useState<ProgressData | null>(null);const [videoFetched, setVideoFetched] = useState(false);const { toast } = useToast();const pollingInterval = useRef<NodeJS.Timeout | null>(null);const timeoutRef = useRef<NodeJS.Timeout | null>(null);const videoFetchedRef = useRef(false);const [ratingInfo, setRatingInfo] = useState<{ rating: string, description: string } | null>(null);const containerRef = useRef<HTMLDivElement>(null);const [isFullscreen, setIsFullscreen] = useState(false);const videoRef = useRef<HTMLVideoElement>(null);// Parse episode infoconst getEpisodeInfo = () => {if (!episode) return { number: '1', title: 'Unknown Episode' };const episodeMatch = episode.match(/E(\d+)\s*-\s*(.+?)(?=\.\w+$)/i);const number = episodeMatch ? episodeMatch[1] : '1';const title = episodeMatch ? episodeMatch[2].trim() : 'Unknown Episode';return { number, title };};const { number: episodeNumber, title: episodeTitle } = getEpisodeInfo();// --- Link Fetching & Polling ---const fetchMovieLink = async () => {if (videoFetchedRef.current) return;try {const response = await getEpisodeLinkByTitle(videoTitle, season, episode);if (response && response.url) {// Stop any polling if runningif (pollingInterval.current) {clearInterval(pollingInterval.current);pollingInterval.current = null;}setVideoUrl(response.url);setVideoFetched(true);videoFetchedRef.current = true;setLoading(false);console.log('Video URL fetched:', response.url);} else if (response && response.progress_url) {startPolling(response.progress_url);} else {console.error('No video URL or progress URL found in response:', response);setError('Video URL not available');}} catch (error) {console.error('Error fetching episode link:', error);setError('Failed to load episode');toast({title: "Error",description: "Could not load the episode",variant: "destructive"});} finally {if (!videoFetchedRef.current && !videoUrl) {setLoading(false);}}};// Fetch content ratings if not provideduseEffect(() => {const fetchRatingInfo = async () => {if (contentRatings && contentRatings.length > 0) {const usRating = contentRatings.find(r => r.country === 'usa') || contentRatings[0];setRatingInfo({rating: usRating.name || 'NR',description: usRating.description || ''});return;}try {const showData = await getTvShowCard(videoTitle);if (showData && showData.data && showData.data.contentRatings) {const ratings = showData.data.contentRatings;const usRating = ratings.find((r: any) => r.country === 'US') || ratings[0];setRatingInfo({rating: usRating?.name || 'TV-14',description: usRating?.description || ''});}} catch (error) {console.error('Failed to fetch show ratings:', error);}};fetchRatingInfo();}, [videoTitle, contentRatings]);const pollProgress = async (progressUrl: string) => {try {const res = await fetch(progressUrl);const data = await res.json();setProgress(data.progress);if (data.progress.progress >= 100) {if (pollingInterval.current) {clearInterval(pollingInterval.current);pollingInterval.current = null;}if (!videoFetchedRef.current) {timeoutRef.current = setTimeout(fetchMovieLink, 5000);}}} catch (error) {console.error('Error polling progress:', error);}};const startPolling = (progressUrl: string) => {if (!pollingInterval.current) {const interval = setInterval(() => pollProgress(progressUrl), 2000);pollingInterval.current = interval;}};useEffect(() => {if (!videoTitle || !season || !episode) {setError('Missing required video information');setLoading(false);return;}// Reset state for new episodesetVideoUrl(null);setVideoFetched(false);videoFetchedRef.current = false;setLoading(true);setProgress(null);setError(null);// Start fetchingfetchMovieLink();return () => {if (pollingInterval.current) clearInterval(pollingInterval.current);if (timeoutRef.current) clearTimeout(timeoutRef.current);};}, [videoTitle, season, episode]);// Add effect to update loading state when videoUrl changesuseEffect(() => {if (videoUrl) {setLoading(false);}}, [videoUrl]);if (error) {4 unmodified lines<p className="text-gray-400 mb-6">{error}</p><buttononClick={onClosePlayer}className="px-6 py-2 bg-theme-primary hover:bg-theme-primary-hover rounded font-medium transition-colors">Back to Show</button>3 unmodified linesif (loading || !videoFetched || !videoUrl) {return (<div className="fixed inset-0 z-50 bg-gradient-to-br from-theme-background-dark to-black flex flex-col items-center justify-center"><div className="text-center max-w-md px-6"><div className="mb-6 flex justify-center">{poster ? (<img src={poster} alt={movieTitle} className="h-auto w-24 rounded-lg shadow-lg" />) : (<div className="flex items-center justify-center h-24 w-24 bg-theme-primary/20 rounded-lg"><Play className="h-12 w-12 text-theme-primary" /></div>)}</div><h2 className="text-2xl md:text-3xl font-bold text-white mb-4">{progress && progress.progress < 100? `Preparing "${episodeTitle}"`: `Loading "${episodeTitle}"`}</h2>{progress ? (<><p className="text-gray-300 mb-4">{progress.progress < 5? 'Initializing your stream...': progress.progress < 100? 'Your stream is being prepared.': 'Almost ready! Starting playback soon...'}</p><div className="relative w-full h-2 bg-gray-800 rounded-full overflow-hidden mb-2"><divclassName="absolute top-0 left-0 h-full bg-gradient-to-r from-theme-primary to-theme-primary-light transition-all duration-300"style={{ width: `${Math.min(100, Math.max(0, progress.progress))}%` }}/></div><p className="text-sm text-gray-400">{Math.round(progress.progress)}% complete</p></>) : (<div className="flex justify-center"><Loader2 className="h-8 w-8 animate-spin text-theme-primary" /></div>)}</div></div>);}// TV Show specific overlay elements that will be passed to VideoPlayerconst tvShowOverlay = (<>{/* Top info bar */}<div className="absolute top-0 left-0 right-0 z-10 flex items-center p-4 bg-gradient-to-b from-black/80 to-transparent"><div><div className="flex items-center">9 unmodified lines<h1 className="text-white text-lg font-bold">{episodeTitle}</h1></div></div>{/* Episodes button */}<div className="absolute top-4 right-16 z-20"><buttononClick={onShowEpisodes}11 unmodified lines<VideoPlayerurl={videoUrl}title={`${videoTitle} - ${season}E${episodeNumber}`}poster={poster || thumbnail}startTime={startTime}onClose={onClosePlayer}onProgressUpdate={onProgressUpdate}2 unmodified lines345678914 unmodified lines2425262728298 unmodified lines3839404142436 unmodified lines50515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761774 unmodified lines1821831841851861871883 unmodified lines1921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662679 unmodified lines27727827928028128228311 unmodified lines2952962972982993003012 unmodified linesimport { useToast } from '@/hooks/use-toast';import { Film, GalleryVerticalEnd, Loader2, Play } from 'lucide-react';import VideoPlayer from './VideoPlayer';import { TvShowCardData } from './ContentCard';interface ProgressData {status: string;14 unmodified linesepisode: string;movieTitle: string;contentRatings?: ContentRating[];poster?: string;startTime?: number;onClosePlayer?: () => void;8 unmodified linesepisode,movieTitle,contentRatings,poster,startTime = 0,onClosePlayer,6 unmodified linesconst [error, setError] = useState<string | null>(null);const [progress, setProgress] = useState<ProgressData | null>(null);const [videoFetched, setVideoFetched] = useState(false);const [showData, setShowData] = useState<TvShowCardData | null>(null);const [selectedImage, setSelectedImage] = useState<string>();const [imageLoaded, setImageLoaded] = useState(false);const [ratingInfo, setRatingInfo] = useState<{ rating: string; description: string } | null>(null);const containerRef = useRef<HTMLDivElement>(null);const videoRef = useRef<HTMLVideoElement>(null);const { toast } = useToast();const pollingInterval = useRef<NodeJS.Timeout | null>(null);const timeoutRef = useRef<NodeJS.Timeout | null>(null);const videoFetchedRef = useRef(false);// Reset imageLoaded whenever we pick a new imageuseEffect(() => {setImageLoaded(false);}, [selectedImage]);// Parse episode infoconst getEpisodeInfo = () => {if (!episode) return { number: '1', title: 'Unknown Episode' };const match = episode.match(/E(\d+)\s*-\s*(.+?)(?=\.\w+$)/i);return {number: match ? match[1] : '1',title: match ? match[2].trim() : 'Unknown Episode'};};const { number: episodeNumber, title: episodeTitle } = getEpisodeInfo();// Random image selector with fallbackconst selectRandomImage = (cardData: TvShowCardData) => {if (cardData.banner?.length) {return cardData.banner[Math.floor(Math.random() * cardData.banner.length)].image;}if (cardData.portrait?.length) {return cardData.portrait[Math.floor(Math.random() * cardData.portrait.length)].image;}return cardData.image;};// Fetch or poll for the video URLconst fetchMovieLink = async () => {if (videoFetchedRef.current) return;try {const response = await getEpisodeLinkByTitle(videoTitle, season, episode);if (response.url) {pollingInterval.current && clearInterval(pollingInterval.current);setVideoUrl(response.url);setVideoFetched(true);videoFetchedRef.current = true;setLoading(false);} else if (response.progress_url) {const poll = async () => {try {const res = await fetch(response.progress_url);const data = await res.json();setProgress(data.progress);if (data.progress.progress >= 100) {pollingInterval.current && clearInterval(pollingInterval.current);timeoutRef.current = setTimeout(fetchMovieLink, 5000);}} catch (e) {console.error(e);}};pollingInterval.current = setInterval(poll, 2000);} else {throw new Error('No URL or progress URL');}} catch (e) {console.error(e);setError('Failed to load episode');toast({ title: 'Error', description: 'Could not load the episode', variant: 'destructive' });setLoading(false);}};// Main init: fetch TV show card, then fetch linkuseEffect(() => {if (!videoTitle || !season || !episode) {setError('Missing required video information');setLoading(false);return;}setLoading(true);setError(null);setVideoUrl(null);setVideoFetched(false);videoFetchedRef.current = false;setProgress(null);const init = async () => {try {const data = await getTvShowCard(videoTitle);setShowData(data);const img = selectRandomImage(data);setSelectedImage(img);const ratings = data.data?.contentRatings || contentRatings || [];if (ratings.length) {const us = ratings.find(r => r.country === 'usa') || ratings[0];setRatingInfo({ rating: us.name || 'NR', description: us.description || '' });}} catch (e) {console.error('Show card fetch error:', e);setError('Failed to load show data');toast({ title: 'Error', description: 'Could not load show data', variant: 'destructive' });setLoading(false);return;}await fetchMovieLink();};init();return () => {pollingInterval.current && clearInterval(pollingInterval.current);timeoutRef.current && clearTimeout(timeoutRef.current);};}, [videoTitle, season, episode]);useEffect(() => {if (videoUrl) setLoading(false);}, [videoUrl]);if (error) {4 unmodified lines<p className="text-gray-400 mb-6">{error}</p><buttononClick={onClosePlayer}className="px-6 py-2 bg-theme-primary hover:bg-theme-primary-hover rounded font-medium">Back to Show</button>3 unmodified linesif (loading || !videoFetched || !videoUrl) {return (<>{/* Hero backdrop with fade-in */}<div className="absolute top-0 left-0 w-full h-full z-50"><div className="absolute inset-0"><imgsrc={selectedImage}onLoad={() => setImageLoaded(true)}onError={(e) => {const target = e.target as HTMLImageElement;target.src = '/placeholder.svg';}}className={`w-full h-full object-cover transition-opacity duration-700 ease-in-out ${imageLoaded ? 'opacity-100' : 'opacity-0'}`}/><div className="absolute inset-0 bg-gradient-to-t from-netflix-black via-netflix-black/50 to-transparent" /><div className="absolute inset-0 bg-gradient-to-r from-netflix-black/80 via-netflix-black/40 to-transparent" /></div></div><div className="fixed inset-0 z-50 flex flex-col items-center backdrop-blur-sm justify-center"><div className="text-center max-w-md px-6"><div className="mb-6 flex justify-center">{poster ? (<img src={poster} alt={movieTitle} className="h-auto w-24 rounded-lg shadow-lg" />) : (<div className="flex items-center justify-center h-24 w-24 bg-theme-primary/20 rounded-lg"><Play className="h-12 w-12 text-theme-primary" /></div>)}</div><h2 className="text-2xl md:text-3xl font-bold text-white mb-4">{progress && progress.progress < 100? `Preparing "${episodeTitle}"`: `Loading "${episodeTitle}"`}</h2>{progress ? (<><p className="text-gray-300 mb-4">{progress.progress < 5? 'Initializing your stream...': progress.progress < 100? 'Your stream is being prepared.': 'Almost ready! Starting playback soon...'}</p><div className="relative w-full h-2 bg-gray-800 rounded-full overflow-hidden mb-2"><divclassName="absolute top-0 left-0 h-full bg-gradient-to-r from-theme-primary to-theme-primary-light transition-all duration-300"style={{ width: `${Math.min(100, Math.max(0, progress.progress))}%` }}/></div><p className="text-sm text-gray-400">{Math.round(progress.progress)}% complete</p></>) : (<div className="flex justify-center"><Loader2 className="h-8 w-8 animate-spin text-theme-primary" /></div>)}</div></div></>);}const tvShowOverlay = (<><div className="absolute top-0 left-0 right-0 z-10 flex items-center p-4 bg-gradient-to-b from-black/80 to-transparent"><div><div className="flex items-center">9 unmodified lines<h1 className="text-white text-lg font-bold">{episodeTitle}</h1></div></div><div className="absolute top-4 right-16 z-20"><buttononClick={onShowEpisodes}11 unmodified lines<VideoPlayerurl={videoUrl}title={`${videoTitle} - ${season}E${episodeNumber}`}poster={selectedImage}startTime={startTime}onClose={onClosePlayer}onProgressUpdate={onProgressUpdate}
10 unmodified lines1112131415161710 unmodified lines// Type for my list itemsexport interface MyListItem {id: string;title: string;type: 'movie' | 'tvshow';addedAt: string;10 unmodified lines11121314151610 unmodified lines// Type for my list itemsexport interface MyListItem {title: string;type: 'movie' | 'tvshow';addedAt: string;
409 unmodified lines410411412413414415416417409 unmodified linesepisode={selectedEpisode}movieTitle={title || ''}contentRatings={showInfo?.data?.contentRatings || []}thumbnail={showInfo?.data?.image || showInfo?.data?.poster_path}poster={showInfo?.data?.poster_path}startTime={getStartTime()}onClosePlayer={handleBack}onProgressUpdate={handleProgressUpdate}409 unmodified lines410411412413414415409 unmodified linesepisode={selectedEpisode}movieTitle={title || ''}contentRatings={showInfo?.data?.contentRatings || []}startTime={getStartTime()}onClosePlayer={handleBack}onProgressUpdate={handleProgressUpdate}
frontend/netlify.tomlAdded+6
frontend/src/components/ContentCard.tsx+6-6
frontend/src/components/HeroSection.tsx+4-4
frontend/src/components/MoviePlayer.tsx+140-140
frontend/src/components/TVShowPlayer.tsx+146-159
frontend/src/lib/storage.ts-1
frontend/src/pages/TvShowPlayerPage.tsx-2