Ajusta função
This commit is contained in:
32
main.py
32
main.py
@@ -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:
|
||||||
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:
|
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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user