File size: 3,822 Bytes
e91dd89
 
fdaf06d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e91dd89
fdaf06d
 
 
 
 
 
 
 
 
 
 
 
 
e91dd89
fdaf06d
e91dd89
 
fdaf06d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e91dd89
 
fdaf06d
 
 
 
 
 
 
e91dd89
fdaf06d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e91dd89
fdaf06d
 
 
 
 
e91dd89
fdaf06d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import gradio as gr
import os
import tempfile
from pathlib import Path
import yt_dlp


# HF persistent storage
DOWNLOAD_DIR = Path(tempfile.gettempdir()) / "downloads"
DOWNLOAD_DIR.mkdir(exist_ok=True)


def download_video(url, quality, audio_only):
    """Download from any supported site."""
    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:
                filename = filename.replace('.webm', '.mp3').replace('.m4a', '.mp3')
            
            fpath = Path(filename)
            size_mb = fpath.stat().st_size / 1024 / 1024 if fpath.exists() else 0
            
            # HF mein file return karna padega
            return str(filename), f"βœ… Done!\nTitle: {info.get('title', 'Unknown')}\nSize: {size_mb:.1f} MB\nBy: {info.get('uploader', 'Unknown')}"
    
    except Exception as e:
        return None, f"❌ Error: {str(e)[:300]}"


def get_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)
            return f"""
🎬 **{info.get('title', 'Unknown')}**
πŸ‘€ Uploader: {info.get('uploader', 'Unknown')}
⏱️ Duration: {info.get('duration', 0)//60}m {info.get('duration', 0)%60}s
πŸ‘οΈ Views: {info.get('view_count', 0):,}
πŸ“Ί Platform: {info.get('extractor', 'Unknown')}
            """
    except Exception as e:
        return f"❌ Error: {str(e)[:200]}"


# ─── GRADIO UI ───
with gr.Blocks(title="☒️ Nuclear Downloader", theme=gr.themes.Soft()) as demo:
    gr.Markdown("""
    # ☒️ Nuclear Video Downloader
    ### YouTube | Instagram | TikTok | Facebook | Twitter | Reddit | Vimeo | +1000 sites
    """)
    
    with gr.Row():
        with gr.Column(scale=1):
            url_input = gr.Textbox(
                label="πŸ”— Video URL",
                placeholder="https://...",
                lines=2
            )
            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_info, inputs=url_input, outputs=status_text)
    download_btn.click(
        fn=download_video,
        inputs=[url_input, quality, audio_only],
        outputs=[output_file, status_text]
    )
    
    gr.Markdown("""
    ---
    β˜• Made for LO
    """)

demo.launch()