import os import gradio as gr from pathlib import Path import yt_dlp DOWNLOAD_DIR = Path("downloads") DOWNLOAD_DIR.mkdir(exist_ok=True) def download_video(url, quality, audio_only, platform): if not url.strip(): return None, "❌ URL daalo!" output_template = str(DOWNLOAD_DIR / "%(title)s.%(ext)s") opts = { "outtmpl": output_template, "quiet": True, "no_warnings": True, } if audio_only: opts["format"] = "bestaudio/best" opts["postprocessors"] = [{ "key": "FFmpegExtractAudio", "preferredcodec": "mp3", "preferredquality": "320", }] elif quality == "Best": opts["format"] = "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" elif quality == "Worst": opts["format"] = "worst" else: h = quality.replace("p", "") opts["format"] = f"bestvideo[height<={h}][ext=mp4]+bestaudio[ext=m4a]/best[height<={h}]" # cookies wala part HF pe kaam nahi karta — remove kiya # Instagram/TikTok ke liye cookies.txt method use karna padega alag se try: with yt_dlp.YoutubeDL(opts) as ydl: info = ydl.extract_info(url, download=True) filename = ydl.prepare_filename(info) if audio_only: for ext in [".webm", ".m4a"]: filename = filename.replace(ext, ".mp3") fpath = Path(filename) size_mb = fpath.stat().st_size / 1024 / 1024 if fpath.exists() else 0 return str(filename), ( f"✅ Done!\n" f"Title: {info.get('title', 'Unknown')}\n" f"Size: {size_mb:.1f} MB\n" f"By: {info.get('uploader', 'Unknown')}" ) except Exception as e: return None, f"❌ Error: {str(e)[:300]}" def get_video_info(url): if not url.strip(): return "❌ URL daalo!" try: with yt_dlp.YoutubeDL({"quiet": True}) as ydl: info = ydl.extract_info(url, download=False) dur = info.get("duration", 0) or 0 return ( f"🎬 {info.get('title', 'Unknown')}\n" f"👤 Uploader: {info.get('uploader', 'Unknown')}\n" f"⏱️ Duration: {dur // 60}m {dur % 60}s\n" f"👁️ Views: {info.get('view_count', 0):,}\n" f"📺 Platform: {info.get('extractor', 'Unknown')}" ) except Exception as e: return f"❌ Error: {str(e)[:300]}" with gr.Blocks(title="☢️ Nuclear Downloader") as app: gr.Markdown(""" # ☢️ Nuclear Video Downloader ### YouTube | Instagram | TikTok | Facebook | Twitter | Reddit | +1000 sites """) with gr.Row(): with gr.Column(scale=1): url_input = gr.Textbox( label="🔗 Video URL", placeholder="https://...", lines=2 ) platform = gr.Dropdown( label="📱 Platform", choices=["Auto-Detect", "YouTube", "Instagram", "TikTok", "Facebook", "Twitter/X", "Reddit", "Vimeo"], value="Auto-Detect" ) quality = gr.Dropdown( label="🎞️ Quality", choices=["Best", "1080p", "720p", "480p", "360p", "Worst"], value="Best" ) audio_only = gr.Checkbox(label="🎵 Audio Only (MP3)", value=False) with gr.Row(): info_btn = gr.Button("ℹ️ Get Info", variant="secondary") download_btn = gr.Button("⬇️ Download", variant="primary") with gr.Column(scale=1): output_file = gr.File(label="📥 Downloaded File") status_text = gr.Textbox(label="📋 Status", lines=6, interactive=False) info_btn.click(fn=get_video_info, inputs=url_input, outputs=status_text) download_btn.click( fn=download_video, inputs=[url_input, quality, audio_only, platform], outputs=[output_file, status_text] ) gr.Markdown("---\n⚠️ Personal use only. Respect copyright laws.") app.launch()