diff --git a/main.py b/main.py index 70937b4..c849a82 100644 --- a/main.py +++ b/main.py @@ -186,16 +186,16 @@ def download_video( "no_warnings": True, "ignoreerrors": False, "noplaylist": True, - "format": fmt_expr, "merge_output_format": "mp4", "force_ipv4": True, "geo_bypass": True, - "extractor_args": { - "youtube": { - "player_client": ["android"], - "player_skip": ["webpage"] - } + "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", }, + "hls_prefer_native": True, + "concurrent_fragment_downloads": 1, } try: @@ -204,7 +204,6 @@ def download_video( if not info: 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": entries = info.get("entries") or [] if not entries: @@ -290,4 +289,32 @@ def search_youtube_yt_dlp( return {"results": results} except Exception as e: - raise HTTPException(status_code=500, detail=f"Erro ao buscar vídeos: {e}") \ No newline at end of file + 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]}