From 8577e45b1dd9c0c29d5cd08f23b82b49a9d6e222 Mon Sep 17 00:00:00 2001 From: LeoMortari Date: Sun, 28 Sep 2025 01:17:07 -0300 Subject: [PATCH] Ajuste download --- main.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/main.py b/main.py index 9e46c8e..1382138 100644 --- a/main.py +++ b/main.py @@ -188,7 +188,20 @@ def download_video( try: with YoutubeDL(ydl_opts) as ydl: 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) + if not title: + title = f"video_{unique_id[:8]}" + clean_title = unidecode(title) clean_title = re.sub(r"[^\w\s-]", "", clean_title) clean_title = clean_title.replace(" ", "_")