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(" ", "_")