Update app.py
Browse files
app.py
CHANGED
@@ -251,13 +251,31 @@ async def get_track_download_url(video_url: str) -> str:
|
|
251 |
async def extract_video_info(video_url: str) -> str:
|
252 |
api_url = f'https://yt-dl-web.vercel.app/api/info?url={video_url}'
|
253 |
session = cloudscraper.create_scraper()
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
|
262 |
|
263 |
@app.post("/test")
|
|
|
251 |
async def extract_video_info(video_url: str) -> str:
|
252 |
api_url = f'https://yt-dl-web.vercel.app/api/info?url={video_url}'
|
253 |
session = cloudscraper.create_scraper()
|
254 |
+
try:
|
255 |
+
response = session.get(api_url, timeout=20)
|
256 |
+
logger.info(response)
|
257 |
+
if response.status_code == 200:
|
258 |
+
json_response = response.json()
|
259 |
+
result = []
|
260 |
+
# 检查 formats 列表是否存在且不为空
|
261 |
+
if 'formats' in json_response:
|
262 |
+
for format_item in json_response['formats']:
|
263 |
+
format_url = format_item.get('url')
|
264 |
+
format_id = format_item.get('format_id')
|
265 |
+
if format_id and format_url:
|
266 |
+
result.append({
|
267 |
+
"url": format_url,
|
268 |
+
"format_id": format_id
|
269 |
+
})
|
270 |
+
title = json_response.get('title')
|
271 |
+
return result
|
272 |
+
else:
|
273 |
+
return {"error": "No formats available"}
|
274 |
+
else:
|
275 |
+
return {"error": f"Request failed with status code {response.status_code}"}
|
276 |
+
except Exception as e:
|
277 |
+
logger.error(f"An error occurred: {e}")
|
278 |
+
return {"error": str(e)}
|
279 |
|
280 |
|
281 |
@app.post("/test")
|