Update app.py
Browse files
app.py
CHANGED
@@ -549,29 +549,30 @@ async def download_high_quality_video(request: Request):
|
|
549 |
}
|
550 |
|
551 |
if is_youtube_url:
|
552 |
-
|
|
|
553 |
if dl_url and "http" in dl_url:
|
554 |
return {"url": dl_url, "requests_remaining": rate_limiter.max_requests - rate_limiter.get_current_count(user_ip)}
|
555 |
else:
|
556 |
return {
|
557 |
"error": "Failed to Fetch the video."
|
558 |
}
|
559 |
-
|
560 |
-
else:
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
|
576 |
|
577 |
|
|
|
549 |
}
|
550 |
|
551 |
if is_youtube_url:
|
552 |
+
ydl_opts["cookiefile"] = "firefox-cookies.txt"
|
553 |
+
'''dl_url = await get_audio_download_url(video_url, quality)
|
554 |
if dl_url and "http" in dl_url:
|
555 |
return {"url": dl_url, "requests_remaining": rate_limiter.max_requests - rate_limiter.get_current_count(user_ip)}
|
556 |
else:
|
557 |
return {
|
558 |
"error": "Failed to Fetch the video."
|
559 |
}
|
560 |
+
'''
|
561 |
+
# else:
|
562 |
+
await run_in_threadpool(lambda: yt_dlp.YoutubeDL(ydl_opts).download([video_url]))
|
563 |
+
|
564 |
+
downloaded_files = list(Path(global_download_dir).glob(f"*_{timestamp}.mp4"))
|
565 |
+
if not downloaded_files:
|
566 |
+
return {"error": "Download failed"}
|
567 |
+
|
568 |
+
downloaded_file = downloaded_files[0]
|
569 |
+
encoded_filename = urllib.parse.quote(downloaded_file.name)
|
570 |
+
download_url = f"{BASE_URL}/file/{encoded_filename}"
|
571 |
+
|
572 |
+
|
573 |
+
gc.collect()
|
574 |
+
|
575 |
+
return {"url": download_url, "requests_remaining": rate_limiter.max_requests - rate_limiter.get_current_count(user_ip)}
|
576 |
|
577 |
|
578 |
|