Update app.py
Browse files
app.py
CHANGED
|
@@ -1,87 +1,89 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
from pathlib import Path
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
DOWNLOAD_DIR = Path("/content/downloads")
|
| 7 |
DOWNLOAD_DIR.mkdir(exist_ok=True)
|
| 8 |
|
| 9 |
-
|
| 10 |
def download_video(url, quality, audio_only, platform):
|
| 11 |
if not url.strip():
|
| 12 |
return None, "β URL daalo!"
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
output_template = str(DOWNLOAD_DIR / '%(title)s.%(ext)s')
|
| 17 |
-
|
| 18 |
opts = {
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
}
|
| 23 |
-
|
| 24 |
if audio_only:
|
| 25 |
-
opts[
|
| 26 |
-
opts[
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
}]
|
| 31 |
elif quality == "Best":
|
| 32 |
-
opts[
|
| 33 |
elif quality == "Worst":
|
| 34 |
-
opts[
|
| 35 |
else:
|
| 36 |
-
h = quality.replace(
|
| 37 |
-
opts[
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
try:
|
| 43 |
with yt_dlp.YoutubeDL(opts) as ydl:
|
| 44 |
info = ydl.extract_info(url, download=True)
|
| 45 |
filename = ydl.prepare_filename(info)
|
| 46 |
-
|
| 47 |
if audio_only:
|
| 48 |
-
|
| 49 |
-
|
|
|
|
| 50 |
fpath = Path(filename)
|
| 51 |
size_mb = fpath.stat().st_size / 1024 / 1024 if fpath.exists() else 0
|
| 52 |
-
|
| 53 |
-
return str(filename),
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
except Exception as e:
|
| 56 |
-
return None, f"β Error: {str(e)[:
|
| 57 |
|
| 58 |
|
| 59 |
def get_video_info(url):
|
| 60 |
if not url.strip():
|
| 61 |
return "β URL daalo!"
|
| 62 |
-
|
| 63 |
-
import yt_dlp
|
| 64 |
try:
|
| 65 |
-
with yt_dlp.YoutubeDL({
|
| 66 |
info = ydl.extract_info(url, download=False)
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
| 74 |
except Exception as e:
|
| 75 |
-
return f"β Error: {str(e)[:
|
| 76 |
|
| 77 |
|
| 78 |
-
# βββ GRADIO UI βββ
|
| 79 |
with gr.Blocks(title="β’οΈ Nuclear Downloader") as app:
|
| 80 |
gr.Markdown("""
|
| 81 |
# β’οΈ Nuclear Video Downloader
|
| 82 |
### YouTube | Instagram | TikTok | Facebook | Twitter | Reddit | +1000 sites
|
| 83 |
""")
|
| 84 |
-
|
| 85 |
with gr.Row():
|
| 86 |
with gr.Column(scale=1):
|
| 87 |
url_input = gr.Textbox(
|
|
@@ -91,7 +93,8 @@ with gr.Blocks(title="β’οΈ Nuclear Downloader") as app:
|
|
| 91 |
)
|
| 92 |
platform = gr.Dropdown(
|
| 93 |
label="π± Platform",
|
| 94 |
-
choices=["Auto-Detect", "YouTube", "Instagram", "TikTok",
|
|
|
|
| 95 |
value="Auto-Detect"
|
| 96 |
)
|
| 97 |
quality = gr.Dropdown(
|
|
@@ -100,35 +103,23 @@ with gr.Blocks(title="β’οΈ Nuclear Downloader") as app:
|
|
| 100 |
value="Best"
|
| 101 |
)
|
| 102 |
audio_only = gr.Checkbox(label="π΅ Audio Only (MP3)", value=False)
|
| 103 |
-
|
| 104 |
with gr.Row():
|
| 105 |
info_btn = gr.Button("βΉοΈ Get Info", variant="secondary")
|
| 106 |
download_btn = gr.Button("β¬οΈ Download", variant="primary")
|
| 107 |
-
|
| 108 |
with gr.Column(scale=1):
|
| 109 |
output_file = gr.File(label="π₯ Downloaded File")
|
| 110 |
status_text = gr.Textbox(label="π Status", lines=6, interactive=False)
|
| 111 |
-
|
| 112 |
info_btn.click(fn=get_video_info, inputs=url_input, outputs=status_text)
|
| 113 |
download_btn.click(
|
| 114 |
fn=download_video,
|
| 115 |
inputs=[url_input, quality, audio_only, platform],
|
| 116 |
outputs=[output_file, status_text]
|
| 117 |
)
|
| 118 |
-
|
| 119 |
-
gr.Markdown("""
|
| 120 |
-
---
|
| 121 |
-
β οΈ **Note:** Link active jab tak Colab runtime chalega.
|
| 122 |
-
""")
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
app.launch(
|
| 129 |
-
server_name="0.0.0.0",
|
| 130 |
-
server_port=7860,
|
| 131 |
-
share=True, # β THIS = Automatic public link
|
| 132 |
-
quiet=True,
|
| 133 |
-
show_error=True
|
| 134 |
-
)
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
from pathlib import Path
|
| 4 |
+
import yt_dlp
|
| 5 |
|
| 6 |
+
DOWNLOAD_DIR = Path("downloads")
|
|
|
|
| 7 |
DOWNLOAD_DIR.mkdir(exist_ok=True)
|
| 8 |
|
| 9 |
+
|
| 10 |
def download_video(url, quality, audio_only, platform):
|
| 11 |
if not url.strip():
|
| 12 |
return None, "β URL daalo!"
|
| 13 |
+
|
| 14 |
+
output_template = str(DOWNLOAD_DIR / "%(title)s.%(ext)s")
|
| 15 |
+
|
|
|
|
|
|
|
| 16 |
opts = {
|
| 17 |
+
"outtmpl": output_template,
|
| 18 |
+
"quiet": True,
|
| 19 |
+
"no_warnings": True,
|
| 20 |
}
|
| 21 |
+
|
| 22 |
if audio_only:
|
| 23 |
+
opts["format"] = "bestaudio/best"
|
| 24 |
+
opts["postprocessors"] = [{
|
| 25 |
+
"key": "FFmpegExtractAudio",
|
| 26 |
+
"preferredcodec": "mp3",
|
| 27 |
+
"preferredquality": "320",
|
| 28 |
}]
|
| 29 |
elif quality == "Best":
|
| 30 |
+
opts["format"] = "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best"
|
| 31 |
elif quality == "Worst":
|
| 32 |
+
opts["format"] = "worst"
|
| 33 |
else:
|
| 34 |
+
h = quality.replace("p", "")
|
| 35 |
+
opts["format"] = f"bestvideo[height<={h}][ext=mp4]+bestaudio[ext=m4a]/best[height<={h}]"
|
| 36 |
+
|
| 37 |
+
# cookies wala part HF pe kaam nahi karta β remove kiya
|
| 38 |
+
# Instagram/TikTok ke liye cookies.txt method use karna padega alag se
|
| 39 |
+
|
| 40 |
try:
|
| 41 |
with yt_dlp.YoutubeDL(opts) as ydl:
|
| 42 |
info = ydl.extract_info(url, download=True)
|
| 43 |
filename = ydl.prepare_filename(info)
|
| 44 |
+
|
| 45 |
if audio_only:
|
| 46 |
+
for ext in [".webm", ".m4a"]:
|
| 47 |
+
filename = filename.replace(ext, ".mp3")
|
| 48 |
+
|
| 49 |
fpath = Path(filename)
|
| 50 |
size_mb = fpath.stat().st_size / 1024 / 1024 if fpath.exists() else 0
|
| 51 |
+
|
| 52 |
+
return str(filename), (
|
| 53 |
+
f"β
Done!\n"
|
| 54 |
+
f"Title: {info.get('title', 'Unknown')}\n"
|
| 55 |
+
f"Size: {size_mb:.1f} MB\n"
|
| 56 |
+
f"By: {info.get('uploader', 'Unknown')}"
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
except Exception as e:
|
| 60 |
+
return None, f"β Error: {str(e)[:300]}"
|
| 61 |
|
| 62 |
|
| 63 |
def get_video_info(url):
|
| 64 |
if not url.strip():
|
| 65 |
return "β URL daalo!"
|
|
|
|
|
|
|
| 66 |
try:
|
| 67 |
+
with yt_dlp.YoutubeDL({"quiet": True}) as ydl:
|
| 68 |
info = ydl.extract_info(url, download=False)
|
| 69 |
+
dur = info.get("duration", 0) or 0
|
| 70 |
+
return (
|
| 71 |
+
f"π¬ {info.get('title', 'Unknown')}\n"
|
| 72 |
+
f"π€ Uploader: {info.get('uploader', 'Unknown')}\n"
|
| 73 |
+
f"β±οΈ Duration: {dur // 60}m {dur % 60}s\n"
|
| 74 |
+
f"ποΈ Views: {info.get('view_count', 0):,}\n"
|
| 75 |
+
f"πΊ Platform: {info.get('extractor', 'Unknown')}"
|
| 76 |
+
)
|
| 77 |
except Exception as e:
|
| 78 |
+
return f"β Error: {str(e)[:300]}"
|
| 79 |
|
| 80 |
|
|
|
|
| 81 |
with gr.Blocks(title="β’οΈ Nuclear Downloader") as app:
|
| 82 |
gr.Markdown("""
|
| 83 |
# β’οΈ Nuclear Video Downloader
|
| 84 |
### YouTube | Instagram | TikTok | Facebook | Twitter | Reddit | +1000 sites
|
| 85 |
""")
|
| 86 |
+
|
| 87 |
with gr.Row():
|
| 88 |
with gr.Column(scale=1):
|
| 89 |
url_input = gr.Textbox(
|
|
|
|
| 93 |
)
|
| 94 |
platform = gr.Dropdown(
|
| 95 |
label="π± Platform",
|
| 96 |
+
choices=["Auto-Detect", "YouTube", "Instagram", "TikTok",
|
| 97 |
+
"Facebook", "Twitter/X", "Reddit", "Vimeo"],
|
| 98 |
value="Auto-Detect"
|
| 99 |
)
|
| 100 |
quality = gr.Dropdown(
|
|
|
|
| 103 |
value="Best"
|
| 104 |
)
|
| 105 |
audio_only = gr.Checkbox(label="π΅ Audio Only (MP3)", value=False)
|
| 106 |
+
|
| 107 |
with gr.Row():
|
| 108 |
info_btn = gr.Button("βΉοΈ Get Info", variant="secondary")
|
| 109 |
download_btn = gr.Button("β¬οΈ Download", variant="primary")
|
| 110 |
+
|
| 111 |
with gr.Column(scale=1):
|
| 112 |
output_file = gr.File(label="π₯ Downloaded File")
|
| 113 |
status_text = gr.Textbox(label="π Status", lines=6, interactive=False)
|
| 114 |
+
|
| 115 |
info_btn.click(fn=get_video_info, inputs=url_input, outputs=status_text)
|
| 116 |
download_btn.click(
|
| 117 |
fn=download_video,
|
| 118 |
inputs=[url_input, quality, audio_only, platform],
|
| 119 |
outputs=[output_file, status_text]
|
| 120 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
+
gr.Markdown("---\nβ οΈ Personal use only. Respect copyright laws.")
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|