This Python script allows you to search and download directly from YouTube as audio files in MP3 format. It's built using the yt_dlp
library for downloading and extracting audio, and urllib
for searching on YouTube.
This project was created to solve a personal need: my radio only supports SD cards and USB sticks, so I can’t connect Spotify via Bluetooth. This script helps create a personalized collection of music in MP3 format that can be easily transferred to these devices for personal usage.
- Search for songs on YouTube using song titles.
- Automatically downloads the best available audio quality in MP3 format.
- Saves the downloaded audio files to a specified destination folder.
To run this script, you'll need the following Python libraries installed:
- uv: An extremely fast Python package and project manager, written in Rust.
- Clone the repository:
git clone https://github.com/rribeiro1/youtube-audio-downloader.git
cd youtube-audio-downloader
- Edit the
songs
list in the script to include the titles of the songs you want to download:
songs = [
"Clipe Oficial - Vem Espírito de Deus",
"Gabriel Guedes - Santo Pra Sempre",
]
- Run the script:
Note
Make sure you downloaded and configured uv accordingly.
uv run main.py
- The downloaded audio files will be saved to the folder specified in the
destination_folder
variable. By default, this is the current directory (./
).
When the script is executed, it will:
- Search for each song title on YouTube.
- Print the first search result.
- Download the audio from the video.
- Save the audio in MP3 format.
Contributions are welcome! If you encounter issues or have suggestions for improvements, feel free to open an issue or submit a pull request.
This script is for personal use only. Ensure you respect copyright laws and the terms of service of YouTube when using this tool.