Spaces:
Paused
Paused
add more logs
Browse files- app/main.py +2 -2
- app/utils.py +4 -1
app/main.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from fastapi import FastAPI, BackgroundTasks
|
| 2 |
from fastapi.responses import FileResponse, JSONResponse
|
| 3 |
from pydantic import BaseModel
|
| 4 |
import uuid
|
|
@@ -17,7 +17,7 @@ def health_check():
|
|
| 17 |
return {"status": "ok", "message": "YouTube Downloader API is running."}
|
| 18 |
|
| 19 |
@app.post("/download")
|
| 20 |
-
async def download(payload:
|
| 21 |
try:
|
| 22 |
video_path = download_video(payload.url, payload.cookie)
|
| 23 |
|
|
|
|
| 1 |
+
from fastapi import FastAPI, BackgroundTasks, HTTPException
|
| 2 |
from fastapi.responses import FileResponse, JSONResponse
|
| 3 |
from pydantic import BaseModel
|
| 4 |
import uuid
|
|
|
|
| 17 |
return {"status": "ok", "message": "YouTube Downloader API is running."}
|
| 18 |
|
| 19 |
@app.post("/download")
|
| 20 |
+
async def download(payload: DownloadRequest): # ✅ sửa lại đúng tên class
|
| 21 |
try:
|
| 22 |
video_path = download_video(payload.url, payload.cookie)
|
| 23 |
|
app/utils.py
CHANGED
|
@@ -21,17 +21,20 @@ def download_video(url: str, cookie: str = None) -> str:
|
|
| 21 |
ydl_opts["cookiefile"] = cookie_file
|
| 22 |
|
| 23 |
try:
|
|
|
|
| 24 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 25 |
info = ydl.extract_info(url, download=True)
|
| 26 |
|
| 27 |
if not os.path.exists(output_path):
|
| 28 |
raise RuntimeError("Download finished but output file not found.")
|
| 29 |
|
|
|
|
| 30 |
return output_path
|
| 31 |
|
| 32 |
except Exception as e:
|
| 33 |
print("🔥 Download failed:", str(e))
|
| 34 |
raise
|
| 35 |
finally:
|
| 36 |
-
if cookie and os.path.exists(cookie_file):
|
| 37 |
os.remove(cookie_file)
|
|
|
|
|
|
| 21 |
ydl_opts["cookiefile"] = cookie_file
|
| 22 |
|
| 23 |
try:
|
| 24 |
+
print(f"📥 Downloading video from {url} to {output_path}")
|
| 25 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 26 |
info = ydl.extract_info(url, download=True)
|
| 27 |
|
| 28 |
if not os.path.exists(output_path):
|
| 29 |
raise RuntimeError("Download finished but output file not found.")
|
| 30 |
|
| 31 |
+
print(f"✅ Video downloaded successfully: {output_path}")
|
| 32 |
return output_path
|
| 33 |
|
| 34 |
except Exception as e:
|
| 35 |
print("🔥 Download failed:", str(e))
|
| 36 |
raise
|
| 37 |
finally:
|
| 38 |
+
if cookie and 'cookie_file' in locals() and os.path.exists(cookie_file):
|
| 39 |
os.remove(cookie_file)
|
| 40 |
+
print("🧹 Temporary cookie file removed.")
|