Add functionality to retrieve video title and description using yt-dlp
This commit is contained in:
parent
344fd5809a
commit
8706a4f3f7
41
main.py
41
main.py
@ -812,13 +812,50 @@ def stream_endpoint(video_id: str):
|
||||
|
||||
# Determinar el tipo de URL obtenida
|
||||
url_type = "unknown"
|
||||
if "m3u8" in stream_url.lower():
|
||||
if stream_url and "m3u8" in stream_url.lower():
|
||||
url_type = "m3u8/hls"
|
||||
elif "googlevideo.com" in stream_url:
|
||||
elif stream_url and "googlevideo.com" in stream_url:
|
||||
url_type = "direct/mp4"
|
||||
|
||||
# Obtener title y description con yt-dlp --dump-json
|
||||
title = None
|
||||
description = None
|
||||
try:
|
||||
_cookie_mgr = CookieManager()
|
||||
_cookiefile = _cookie_mgr.get_cookiefile_path()
|
||||
_cookies_path = _cookiefile or os.getenv('API_COOKIES_PATH', DEFAULT_COOKIES_PATH)
|
||||
_proxy = os.getenv('API_PROXY', DEFAULT_PROXY) or None
|
||||
|
||||
_cmd = [
|
||||
"yt-dlp",
|
||||
"--skip-download",
|
||||
"--dump-json",
|
||||
"--no-warnings",
|
||||
"--extractor-args", "youtube:player_client=android",
|
||||
f"https://www.youtube.com/watch?v={video_id}"
|
||||
]
|
||||
if _cookiefile:
|
||||
_cmd.extend(["--cookies", _cookiefile])
|
||||
if _proxy:
|
||||
_cmd.extend(["--proxy", _proxy])
|
||||
|
||||
_proc = subprocess.run(_cmd, capture_output=True, text=True, timeout=60)
|
||||
if _proc.returncode == 0 and _proc.stdout:
|
||||
_meta = json.loads(_proc.stdout)
|
||||
title = _meta.get("title")
|
||||
description = _meta.get("description")
|
||||
except Exception:
|
||||
pass
|
||||
finally:
|
||||
try:
|
||||
_cookie_mgr.cleanup()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return {
|
||||
"video_id": video_id,
|
||||
"title": title,
|
||||
"description": description,
|
||||
"stream_url": stream_url,
|
||||
"url_type": url_type,
|
||||
"youtube_url": f"https://www.youtube.com/watch?v={video_id}",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user