Add endpoints de formato
This commit is contained in:
43
main.py
43
main.py
@@ -186,16 +186,16 @@ def download_video(
|
|||||||
"no_warnings": True,
|
"no_warnings": True,
|
||||||
"ignoreerrors": False,
|
"ignoreerrors": False,
|
||||||
"noplaylist": True,
|
"noplaylist": True,
|
||||||
"format": fmt_expr,
|
|
||||||
"merge_output_format": "mp4",
|
"merge_output_format": "mp4",
|
||||||
"force_ipv4": True,
|
"force_ipv4": True,
|
||||||
"geo_bypass": True,
|
"geo_bypass": True,
|
||||||
"extractor_args": {
|
"extractor_args": {"youtube": {"player_client": ["android"], "player_skip": ["webpage"]}},
|
||||||
"youtube": {
|
"http_headers": {
|
||||||
"player_client": ["android"],
|
"Accept-Language": "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7",
|
||||||
"player_skip": ["webpage"]
|
"User-Agent": "com.google.android.youtube/19.17.36 (Linux; U; Android 13) gzip",
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
"hls_prefer_native": True,
|
||||||
|
"concurrent_fragment_downloads": 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -204,7 +204,6 @@ def download_video(
|
|||||||
if not info:
|
if not info:
|
||||||
raise HTTPException(status_code=404, detail="Não foi possível obter informações do vídeo.")
|
raise HTTPException(status_code=404, detail="Não foi possível obter informações do vídeo.")
|
||||||
|
|
||||||
# Se por acaso vier um wrapper de playlist, pegue a primeira entrada
|
|
||||||
if info.get("_type") == "playlist":
|
if info.get("_type") == "playlist":
|
||||||
entries = info.get("entries") or []
|
entries = info.get("entries") or []
|
||||||
if not entries:
|
if not entries:
|
||||||
@@ -290,4 +289,32 @@ def search_youtube_yt_dlp(
|
|||||||
return {"results": results}
|
return {"results": results}
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail=f"Erro ao buscar vídeos: {e}")
|
raise HTTPException(status_code=500, detail=f"Erro ao buscar vídeos: {e}")
|
||||||
|
|
||||||
|
@app.get("/list-formats")
|
||||||
|
def list_formats(url: str):
|
||||||
|
opts = {
|
||||||
|
"quiet": False,
|
||||||
|
"no_warnings": False,
|
||||||
|
"noplaylist": True,
|
||||||
|
"force_ipv4": True,
|
||||||
|
"geo_bypass": True,
|
||||||
|
"extractor_args": {"youtube": {"player_client": ["android"], "player_skip": ["webpage"]}},
|
||||||
|
"http_headers": {
|
||||||
|
"Accept-Language": "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7",
|
||||||
|
"User-Agent": "com.google.android.youtube/19.17.36 (Linux; U; Android 13) gzip",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
with YoutubeDL(opts) as y:
|
||||||
|
info = y.extract_info(url, download=False)
|
||||||
|
fmts = info.get("formats") or []
|
||||||
|
brief = [{
|
||||||
|
"id": f.get("format_id"),
|
||||||
|
"ext": f.get("ext"),
|
||||||
|
"h": f.get("height"),
|
||||||
|
"fps": f.get("fps"),
|
||||||
|
"v": f.get("vcodec"),
|
||||||
|
"a": f.get("acodec"),
|
||||||
|
"tbr": f.get("tbr"),
|
||||||
|
} for f in fmts]
|
||||||
|
return {"total": len(brief), "formats": brief[:60]}
|
||||||
|
|||||||
Reference in New Issue
Block a user