From a12b3b09e1d8632a2b351ab5aeb3b4e63eb2cea7 Mon Sep 17 00:00:00 2001 From: LeoMortari Date: Sat, 27 Sep 2025 00:27:00 -0300 Subject: [PATCH] =?UTF-8?q?Ajusta=20fun=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index dbdc117..b4a04bb 100644 --- a/main.py +++ b/main.py @@ -69,16 +69,38 @@ def get_video_metadata( target = f"https://www.youtube.com/watch?v={videoId}" ydl_opts = { - "quiet": True, - "extract_flat": "in_playlist", - "skip_download": True, + 'quiet': True, + 'no_warnings': True, + 'skip_download': True, + 'extract_flat': True, + 'force_generic_extractor': True, + 'format': 'best', + 'nocheckcertificate': True, + 'ignoreerrors': True, + 'no_color': True, + 'extract_flat': 'in_playlist', + 'force_generic_extractor': True, } try: with YoutubeDL(ydl_opts) as ydl: - info = ydl.extract_info(target, download=False) + # Primeiro tenta extrair as informações básicas + info = ydl.extract_info(target, download=False, process=False) + + # Se for um vídeo, tenta obter mais detalhes + if info.get('_type') == 'url' or 'entries' not in info: + info = ydl.extract_info(target, download=False) + + # Se ainda assim não tiver as informações básicas, retorna erro + if not info: + raise Exception("Não foi possível extrair as informações do vídeo") + except Exception as e: - raise HTTPException(status_code=500, detail=f"Erro ao extrair metadata: {e}") + error_msg = str(e).replace('\n', ' ').strip() + raise HTTPException( + status_code=500, + detail=f"Erro ao processar o vídeo: {error_msg}" + ) return info