Ajuste download
This commit is contained in:
13
main.py
13
main.py
@@ -188,7 +188,20 @@ def download_video(
|
|||||||
try:
|
try:
|
||||||
with YoutubeDL(ydl_opts) as ydl:
|
with YoutubeDL(ydl_opts) as ydl:
|
||||||
base = ydl.extract_info(target, download=False)
|
base = ydl.extract_info(target, download=False)
|
||||||
|
|
||||||
|
if not base:
|
||||||
|
raise HTTPException(status_code=404, detail="Não foi possível obter informações do vídeo. Verifique a URL ou o ID do vídeo.")
|
||||||
|
|
||||||
|
if '_type' in base and base['_type'] == 'playlist':
|
||||||
|
if 'entries' in base and len(base['entries']) > 0:
|
||||||
|
base = base['entries'][0]
|
||||||
|
else:
|
||||||
|
raise HTTPException(status_code=404, detail="Nenhum vídeo encontrado na playlist.")
|
||||||
|
|
||||||
title = base.get("title", unique_id)
|
title = base.get("title", unique_id)
|
||||||
|
if not title:
|
||||||
|
title = f"video_{unique_id[:8]}"
|
||||||
|
|
||||||
clean_title = unidecode(title)
|
clean_title = unidecode(title)
|
||||||
clean_title = re.sub(r"[^\w\s-]", "", clean_title)
|
clean_title = re.sub(r"[^\w\s-]", "", clean_title)
|
||||||
clean_title = clean_title.replace(" ", "_")
|
clean_title = clean_title.replace(" ", "_")
|
||||||
|
|||||||
Reference in New Issue
Block a user