Chrunos commited on
Commit
9c06b1d
·
verified ·
1 Parent(s): c98363a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -26,6 +26,7 @@ from starlette.responses import JSONResponse
26
  import logging
27
  import gc
28
  from typing import Dict, Any
 
29
 
30
  tmp_dir = tempfile.gettempdir()
31
  BASE_URL = "https://chrunos-zam.hf.space"
@@ -173,6 +174,8 @@ def get_user_ip(request: Request) -> str:
173
  return request.client.host
174
 
175
 
 
 
176
  @app.post("/maxs")
177
  async def download_high_quality_video(request: Request):
178
  user_ip = get_user_ip(request)
@@ -186,10 +189,12 @@ async def download_high_quality_video(request: Request):
186
  "url": "https://t.me/chrunoss"
187
  }
188
  )
189
-
 
190
  data = await request.json()
191
  restricted_domain = "chrunos.com"
192
  video_url = data.get('url')
 
193
  if video_url and restricted_domain in video_url:
194
  return {"error": "What is wrong with you?", "url": "https://t.me/chrunoss"}
195
 
@@ -224,10 +229,12 @@ async def download_high_quality_video(request: Request):
224
  'quiet': True,
225
  'no_warnings': True,
226
  'noprogress': True,
227
- 'merge_output_format': 'mp4',
228
- 'cookiefile': cookiefile
229
  }
230
 
 
 
 
231
  await run_in_threadpool(lambda: yt_dlp.YoutubeDL(ydl_opts).download([video_url]))
232
 
233
  downloaded_files = list(Path(global_download_dir).glob(f"*_{timestamp}.mp4"))
 
26
  import logging
27
  import gc
28
  from typing import Dict, Any
29
+ import re
30
 
31
  tmp_dir = tempfile.gettempdir()
32
  BASE_URL = "https://chrunos-zam.hf.space"
 
174
  return request.client.host
175
 
176
 
177
+
178
+
179
  @app.post("/maxs")
180
  async def download_high_quality_video(request: Request):
181
  user_ip = get_user_ip(request)
 
189
  "url": "https://t.me/chrunoss"
190
  }
191
  )
192
+
193
+
194
  data = await request.json()
195
  restricted_domain = "chrunos.com"
196
  video_url = data.get('url')
197
+ is_youtube_url = re.search(r'(youtube\.com|youtu\.be)', video_url) is not None
198
  if video_url and restricted_domain in video_url:
199
  return {"error": "What is wrong with you?", "url": "https://t.me/chrunoss"}
200
 
 
229
  'quiet': True,
230
  'no_warnings': True,
231
  'noprogress': True,
232
+ 'merge_output_format': 'mp4'
 
233
  }
234
 
235
+ if is_youtube_url:
236
+ ydl_opts['cookiefile'] = cookiefile
237
+
238
  await run_in_threadpool(lambda: yt_dlp.YoutubeDL(ydl_opts).download([video_url]))
239
 
240
  downloaded_files = list(Path(global_download_dir).glob(f"*_{timestamp}.mp4"))