diff --git a/projects/YouTube Video Downloader/README.md b/projects/YouTube Video Downloader/README.md new file mode 100644 index 000000000..e2055763f --- /dev/null +++ b/projects/YouTube Video Downloader/README.md @@ -0,0 +1,50 @@ +# youtube_video_downloader + +Este projeto utiliza `yt-dlp` para baixar vídeos do YouTube com a resolução mais alta disponível ou com a resolução escolhida pelo usuário. + +## Descrição + +- **Nome do Script:** `you_tube_analyzer.py` +- **Propósito:** Baixar vídeos do YouTube com alta qualidade. +- **Funcionalidades:** + - Permite ao usuário escolher entre as resoluções disponíveis. + - Seleciona automaticamente a maior resolução disponível, se preferido. + +## Requisitos + +- Python 3 +- yt-dlp + +## Uso + +1. Clone o repositório para sua máquina local. + ```bash + git clone https://github.com/Mrinank-Bhowmick/python-beginner-projects.git + +2. Navegue até o diretório do script + ```bash + cd python-beginner-projects/projects/YouTube\ Video\ Downloader/ + +3. Instale as dependências necessárias. + ```bash + pip install yt-dlp + +4. Execute you_tube_analyzer.py + ```bash + python3 you_tube_analyzer.py + +## Solução de Problemas + +Se você encontrar conflitos de dependências com versões mais recentes, siga os passos +abaixo para configurar um ambiente virtual e instalar as versões específicas necessárias: + +### 1. Crie e ative um ambiente virtual: + ```bash + python3 -m venv meu_ambiente + source meu-ambiente/bin/activate +``` + +### 2. Instale as versões compatíveis das dependências: + ```bash + pip install requests_mock clyent==1.2.1 nbformat==5.4.0 requests==2.28.1 +``` diff --git a/projects/YouTube Video Downloader/you_tube_analyzer.py b/projects/YouTube Video Downloader/you_tube_analyzer.py index 617f34bf0..f928194af 100644 --- a/projects/YouTube Video Downloader/you_tube_analyzer.py +++ b/projects/YouTube Video Downloader/you_tube_analyzer.py @@ -1,6 +1,5 @@ import yt_dlp - def download_youtube_video(video_url): """Downloads a YouTube video using yt-dlp.""" @@ -24,14 +23,15 @@ def download_youtube_video(video_url): ydl_opts["format"] = format_id else: # Select the highest resolution format - highest_resolution = max(formats, key=lambda x: x.get("height", 0)) + highest_resolution = max(formats, key=lambda x: (x.get("height") or 0)) format_id = highest_resolution["format_id"] ydl_opts["format"] = format_id - # Download the video - ydl.download([video_url]) - print("Download complete using yt-dlp!") - + # Update options with selected format + with yt_dlp.YoutubeDL(ydl_opts) as ydl: + ydl.download([video_url]) + print("Downlaod complete using yt-dlp") + if __name__ == "__main__": video_url = input("Enter the URL: ")