deepuurf commited on
Commit
1d97c26
Β·
verified Β·
1 Parent(s): 29eb590

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -65
app.py CHANGED
@@ -1,87 +1,89 @@
1
  import os
2
  import gradio as gr
3
  from pathlib import Path
 
4
 
5
- # ─── SETUP ───
6
- DOWNLOAD_DIR = Path("/content/downloads")
7
  DOWNLOAD_DIR.mkdir(exist_ok=True)
8
 
9
- # ─── DOWNLOADER ENGINE ───
10
  def download_video(url, quality, audio_only, platform):
11
  if not url.strip():
12
  return None, "❌ URL daalo!"
13
-
14
- import yt_dlp
15
-
16
- output_template = str(DOWNLOAD_DIR / '%(title)s.%(ext)s')
17
-
18
  opts = {
19
- 'outtmpl': output_template,
20
- 'quiet': True,
21
- 'no_warnings': True,
22
  }
23
-
24
  if audio_only:
25
- opts['format'] = 'bestaudio/best'
26
- opts['postprocessors'] = [{
27
- 'key': 'FFmpegExtractAudio',
28
- 'preferredcodec': 'mp3',
29
- 'preferredquality': '320',
30
  }]
31
  elif quality == "Best":
32
- opts['format'] = 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best'
33
  elif quality == "Worst":
34
- opts['format'] = 'worst'
35
  else:
36
- h = quality.replace('p', '')
37
- opts['format'] = f'bestvideo[height<={h}][ext=mp4]+bestaudio[ext=m4a]/best[height<={h}]'
38
-
39
- if platform in ["Instagram", "TikTok", "Facebook"]:
40
- opts['cookiesfrombrowser'] = 'chrome'
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
- filename = filename.replace('.webm', '.mp3').replace('.m4a', '.mp3')
49
-
 
50
  fpath = Path(filename)
51
  size_mb = fpath.stat().st_size / 1024 / 1024 if fpath.exists() else 0
52
-
53
- return str(filename), f"βœ… Done!\nTitle: {info.get('title', 'Unknown')}\nSize: {size_mb:.1f} MB\nBy: {info.get('uploader', 'Unknown')}"
54
-
 
 
 
 
 
55
  except Exception as e:
56
- return None, f"❌ Error: {str(e)[:200]}"
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({'quiet': True}) as ydl:
66
  info = ydl.extract_info(url, download=False)
67
- return f"""
68
- 🎬 **{info.get('title', 'Unknown')}**
69
- πŸ‘€ Uploader: {info.get('uploader', 'Unknown')}
70
- ⏱️ Duration: {info.get('duration', 0)//60}m {info.get('duration', 0)%60}s
71
- πŸ‘οΈ Views: {info.get('view_count', 0):,}
72
- πŸ“Ί Platform: {info.get('extractor', 'Unknown')}
73
- """
 
74
  except Exception as e:
75
- return f"❌ Error: {str(e)[:200]}"
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", "Facebook", "Twitter/X", "Reddit", "Vimeo"],
 
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
- # ─── LAUNCH WITH PUBLIC SHARE ───
125
- print("πŸš€ Creating public link...")
126
- print("⏳ Thoda wait karo...")
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()