'use client'; import { useState, useEffect } from 'react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Label } from '@/components/ui/label'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Download, Loader2, Play, Music, Sparkles, Zap, Check } from 'lucide-react'; import { isValidYouTubeUrl } from '@/lib/utils'; import type { VideoInfo, DownloadResponse, VideoFormat, AudioFormat } from '@/lib/types'; export default function Home() { const [url, setUrl] = useState(''); const [loading, setLoading] = useState(false); const [videoInfo, setVideoInfo] = useState(null); const [videoFormat, setVideoFormat] = useState('mp4'); const [audioFormat, setAudioFormat] = useState('mp3'); const [formatType, setFormatType] = useState<'video' | 'audio'>('video'); const [downloadResult, setDownloadResult] = useState(null); const [error, setError] = useState(null); const [mousePos, setMousePos] = useState({ x: 0, y: 0 }); useEffect(() => { const handleMouseMove = (e: MouseEvent) => { const x = (e.clientX / window.innerWidth) * 2 - 1; const y = (e.clientY / window.innerHeight) * 2 - 1; setMousePos({ x, y }); }; window.addEventListener('mousemove', handleMouseMove); return () => window.removeEventListener('mousemove', handleMouseMove); }, []); const handleGetInfo = async () => { if (!url.trim()) { setError('Please enter a YouTube URL'); return; } if (!isValidYouTubeUrl(url)) { setError('Please enter a valid YouTube URL'); return; } setLoading(true); setError(null); setVideoInfo(null); setDownloadResult(null); try { const response = await fetch('/api/info', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url }), }); const data = await response.json(); if (data.success && data.videoInfo) { setVideoInfo(data.videoInfo); } else { setError(data.error || 'Failed to get video information'); } } catch (err: any) { setError(err.message || 'Failed to fetch video info'); } finally { setLoading(false); } }; const handleDownload = async () => { if (!url.trim()) { setError('Please enter a YouTube URL'); return; } if (!isValidYouTubeUrl(url)) { setError('Please enter a valid YouTube URL'); return; } setLoading(true); setError(null); setDownloadResult(null); try { const response = await fetch('/api/download', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url, format: formatType === 'video' ? videoFormat : audioFormat, formatType, }), }); const data: DownloadResponse = await response.json(); if (data.success) { setDownloadResult(data); if (data.videoInfo) { setVideoInfo(data.videoInfo); } } else { setError(data.error || 'Failed to download video'); } } catch (err: any) { setError(err.message || 'Failed to download video'); } finally { setLoading(false); } }; const formatDuration = (seconds: number) => { const mins = Math.floor(seconds / 60); const secs = Math.floor(seconds % 60); return `${mins}:${secs.toString().padStart(2, '0')}`; }; return (
{/* Animated background */}
{/* Header */}
Fast & Free Downloads

Downlink

Download YouTube videos and audio in any format. No limits, no ads, just downloads.

{/* URL Input Card */}
setUrl(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter' && !loading) { handleGetInfo(); } }} className="h-12 px-4 text-base bg-background/50 border-white/10 input-glow rounded-xl placeholder:text-muted-foreground/50" />
{/* Error Display */} {error && (

{error}

)} {/* Video Info Card */} {videoInfo && ( {videoInfo.thumbnail && (
{videoInfo.title}
)}

{videoInfo.title}

{formatDuration(videoInfo.duration)}
)} {/* Download Options Card */} {videoInfo && ( Download Options Choose your format and quality {/* Format Type Toggle */}
{/* Format Selection */}
{formatType === 'video' ? ( ) : ( )}
{/* Download Button */}
)} {/* Success Card */} {downloadResult?.success && downloadResult.downloadUrl && (

Ready to Download

Your file has been prepared

)} {/* Footer */}

Free and open source. No tracking, no ads.

); }