| 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}]" |
|
|
| |
| |
|
|
| 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() |