├── yt_dlp_errors.log ├── LICENSE ├── app.py └── README.md /yt_dlp_errors.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Rivaldo M. Silva 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from fastapi import FastAPI 2 | from fastapi.responses import FileResponse 3 | import yt_dlp 4 | import zipfile 5 | import os 6 | import uuid 7 | import logging 8 | 9 | 10 | logging.basicConfig(filename="yt_dlp_errors.log", level=logging.ERROR) 11 | 12 | 13 | app = FastAPI() 14 | 15 | 16 | ydl_opts = { 17 | 'format': 'bestaudio/best', 18 | 'outtmpl': 'downloads/%(playlist_index)s - %(title)s.%(ext)s', 19 | 'postprocessors': [{ 20 | 'key': 'FFmpegExtractAudio', 21 | 'preferredcodec': 'mp3', 22 | 'preferredquality': '192', 23 | }], 24 | 'ignoreerrors': True, 25 | 'logger': logging.getLogger(), 26 | } 27 | 28 | 29 | @app.post("/download_playlist/") 30 | async def download_playlist(playlist_url: str): 31 | try: 32 | 33 | download_path = "downloads/" 34 | 35 | if not os.path.exists(download_path): 36 | os.makedirs(download_path) 37 | 38 | with yt_dlp.YoutubeDL(ydl_opts) as ydl: 39 | ydl.download([playlist_url]) 40 | 41 | 42 | except Exception as e: 43 | logging.error(f"Erro ao processar a playlist: {str(e)}") 44 | return {"detail": f"Erro ao processar a playlist: {str(e)}"} 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # **BaixeAqui** 2 | 3 | **baixeaqui** é uma API simples construída com FastAPI e yt-dlp para baixar playlists do YouTube em formato MP3 e compactá-las em um arquivo ZIP. Ela ignora erros como vídeos privados e continua o download dos próximos vídeos na playlist. 4 | 5 | ## **Requisitos** 6 | 7 | Antes de rodar a aplicação, você precisa ter o Python instalado e as dependências necessárias. O projeto também utiliza o **yt-dlp** para fazer o download dos vídeos, o **FFmpeg** para converter para MP3 e o **FastAPI** para a API. 8 | 9 | ### **Dependências** 10 | 11 | - Python 3.7 ou superior 12 | - FFmpeg (certifique-se de ter o **FFmpeg** instalado no seu sistema) 13 | 14 | ## **Instalação** 15 | 16 | ## **1. Clonar o repositório** 17 | 18 | ###Clone o repositório para o seu diretório de trabalho: 19 | 20 | ```bash 21 | git clone https://github.com/seu_usuario/baixeaqui.git 22 | cd baixeaqui 23 | 24 | ``` 25 | 26 | ## **2. Instalar as dependências** 27 | ### Execute o seguinte comando para instalar as dependências necessárias: 28 | ```bash 29 | pip install fastapi uvicorn yt-dlp 30 | ``` 31 | 32 | ## **3. Instalar o FFmpeg** 33 | ### Windows: 34 | 35 | Baixe o FFmpeg [aqui](https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip) e extraia o conteúdo. 36 | Adicione o diretório bin do FFmpeg ao PATH do seu sistema. 37 | 38 | ### Linux/MacOS: 39 | 40 | ```bash 41 | Copiar código 42 | sudo apt update 43 | sudo apt install ffmpeg 44 | ``` 45 | 46 | ## **Uso** 47 | ## **1. Rodando o servidor** 48 | 49 | ### Windows: 50 | 51 | ```bash 52 | Copiar código 53 | python -m uvicorn app:app --reload 54 | ``` 55 | ### Linux/MacOS: 56 | ```bash 57 | Copiar código 58 | python3 -m uvicorn app:app --reload 59 | ``` 60 | ### **Isso iniciará o servidor localmente na URL http://127.0.0.1:8000.** 61 | 62 | ## **2. Endpoint para download da playlist** 63 | ### Você pode fazer uma requisição POST para o endpoint /download_playlist/, fornecendo a URL da playlist do YouTube que deseja baixar. 64 | 65 | ### **Exemplo de requisição:** 66 | ```bash 67 | POST http://127.0.0.1:8000/download_playlist/ 68 | 69 | { 70 | "playlist_url": "https://www.youtube.com/playlist?list=OLAK5uy_mxLRWtpm13rbHsw05VcE8-qwJON6DFoTc" 71 | } 72 | ``` 73 | 74 | ![App Screenshot](https://iili.io/2OZtXlp.png) 75 | 76 | ### Isso irá baixar a playlist em formato MP3. 77 | 78 | ## **3. Erros de download** 79 | 80 | ### Se algum vídeo da playlist for privado ou não estiver disponível, o download continuará para os próximos vídeos, e o erro será registrado em um arquivo de log chamado yt_dlp_errors.log. 81 | --------------------------------------------------------------------------------