import gradio as gr import yt_dlp def get_cookie_path(url): if "facebook.com" in url or "fb.watch" in url or "instagram.com" in url: return "cookies-fb.txt" else: # default to YouTube return "cookies-yt.txt" def get_video_url(url): try: cookie_file = get_cookie_path(url) ydl_opts = { 'format': 'best[ext=mp4]/best', 'noplaylist': True, 'cookiefile': cookie_file, 'quiet': True, 'skip_download': True, } with yt_dlp.YoutubeDL(ydl_opts) as ydl: info = ydl.extract_info(url, download=False) video_url = info.get("url", None) title = info.get("title", "Video") if video_url: return f'Click Here to Download' else: return "❌ Could not retrieve the video URL." except Exception as e: return f"❌ Error: {str(e)}" app = gr.Interface( fn=get_video_url, inputs=gr.Textbox(label="Enter Video URL"), outputs=gr.HTML(label="Download Link"), title="Universal Video Downloader", description="Paste a video URL from YouTube, Instagram, or Facebook and get a direct MP4 download link.\nMake sure your cookies are up to date.", theme="compact" ) app.launch()