Ajusta função

This commit is contained in:
LeoMortari
2025-09-27 00:27:00 -03:00
parent 7f3792e0b7
commit a12b3b09e1

30
main.py
View File

@@ -69,16 +69,38 @@ def get_video_metadata(
target = f"https://www.youtube.com/watch?v={videoId}" target = f"https://www.youtube.com/watch?v={videoId}"
ydl_opts = { ydl_opts = {
"quiet": True, 'quiet': True,
"extract_flat": "in_playlist", 'no_warnings': True,
"skip_download": 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: try:
with YoutubeDL(ydl_opts) as ydl: with YoutubeDL(ydl_opts) as ydl:
# 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) 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: 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 return info