File size: 4,182 Bytes
d7f700f 8fcbdfa 1d97c26 bc49965 1d97c26 8fcbdfa bc49965 1d97c26 8fcbdfa 1d97c26 8fcbdfa 1d97c26 8fcbdfa 1d97c26 8fcbdfa 1d97c26 8fcbdfa 1d97c26 8fcbdfa 1d97c26 8fcbdfa 1d97c26 8fcbdfa 1d97c26 8fcbdfa 1d97c26 8fcbdfa 1d97c26 8fcbdfa 1d97c26 8fcbdfa 1d97c26 8fcbdfa 1d97c26 8fcbdfa 1d97c26 d7f700f 8fcbdfa f3cc8a0 8fcbdfa f3cc8a0 1d97c26 f3cc8a0 8fcbdfa 1d97c26 8fcbdfa 1d97c26 8fcbdfa 1d97c26 f3cc8a0 8fcbdfa 1d97c26 8fcbdfa f3cc8a0 d7f700f 1d97c26 | 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 120 121 122 123 124 125 | 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() |