A Docker-based tool to download playlists from YouTube Music and convert them to MP3 format.
- Download entire playlists from YouTube Music
- Convert videos to high-quality MP3 files
- Preserve metadata (title, artist, album)
- Embed album artwork
- Organize downloads by playlist
- Support for multiple playlists
- Network error handling with retries
- Download progress tracking
- Rate limiting to avoid IP blocking
- Comprehensive logging
- Docker
- Docker Compose (optional, but recommended)
-
Clone this repository or download the files
-
Run the setup script to create necessary directories:
# On Linux/Mac chmod +x setup.sh ./setup.sh # On Windows .\setup.ps1
-
Edit the
playlists.txtfile to add your YouTube Music playlist URLs (one per line) -
Run the container using Docker Compose:
docker-compose up
The downloaded MP3 files will be available in the ./downloads directory, and logs in the ./logs directory.
- Edit the
playlists.txtfile with your playlist URLs - Run the container:
docker-compose upTo customize the MP3 quality:
MP3_QUALITY=192k docker-compose upTo enable rate limiting and add verbosity:
RATE_LIMIT=1 VERBOSE=1 docker-compose upTo specify additional arguments:
EXTRA_ARGS="--retries 5" docker-compose upThe application also supports a YAML configuration file. By default, it looks for config.yml in the application directory.
Example configuration:
# Output directory for downloaded files
output_dir: /downloads
# MP3 audio quality (e.g., 128k, 192k, 320k)
quality: 320k
# Enable rate limiting to avoid IP blocking (0=disabled, 1=enabled)
rate_limit: 0
# Maximum number of retries for failed downloads
max_retries: 3
# Log file path (leave empty for console-only logging)
log_file: /logs/ytm-downloader.log
# Verbose logging (0=normal, 1=verbose)
verbose: 0To use a custom configuration file:
CONFIG_FILE=./my-custom-config.yml docker-compose up# Build the Docker image
docker build -t ytm-downloader .
# Download a single playlist
docker run -v "$(pwd)/downloads:/downloads" ytm-downloader "https://music.youtube.com/playlist?list=PLXXXXX"
# Download multiple playlists
docker run -v "$(pwd)/downloads:/downloads" ytm-downloader "https://music.youtube.com/playlist?list=PLXXXX" "https://music.youtube.com/playlist?list=PLyyyy"
# Download playlists from a file
docker run -v "$(pwd)/downloads:/downloads" -v "$(pwd)/playlists.txt:/app/playlists.txt:ro" ytm-downloader -f /app/playlists.txtUsage: python main.py [OPTIONS] [URLS...]
Options:
-o, --output-dir DIR Directory to save downloaded files (default: ./downloads)
-q, --quality QUALITY MP3 audio quality (default: 320k)
-f, --file FILE Text file with playlist URLs (one per line)
-r, --rate-limit Enable rate limiting to avoid IP blocking
--retries NUM Number of retries for failed downloads (default: 3)
--log-file FILE Save logs to a file in addition to console output
-v, --verbose Enable verbose logging
--help Show this help messageThe Docker image follows best practices:
- Uses multi-stage builds to reduce image size
- Runs as a non-root user for security
- Includes only necessary dependencies
- Uses specific version tags for reproducibility
- Properly handles signals for graceful shutdown
MIT
This tool uses:
Contributions are welcome! Please see CONTRIBUTING.md for details on how to contribute to this project.
This project is hosted on GitHub and includes CI/CD through GitHub Actions:
- Fork the Repository: Fork this repository to your GitHub account
- Clone:
git clone https://github.com/yourusername/youtube-music-downloader.git - Install Dependencies: Run the setup script to prepare your environment
- Make Changes: Implement your feature or fix
- Create a Pull Request: Submit your changes for review
The repository includes a GitHub Actions workflow that:
- Builds the Docker image
- Runs linting with flake8
- Tests the Docker container functionality
- Verifies directory structure
This project was developed with the assistance of GitHub Copilot, an AI pair programming tool that helps generate code and provide suggestions during development.
Want to try out the tool? Here are some curated playlists you can download:
| Playlist Name | Description | URL |
|---|---|---|
| Lo-Fi Beats | Perfect background music for coding or studying | https://music.youtube.com/playlist?list=PLQ176FUIyIUaNcDQJjIFL0wp8GW2EA9Xh |
| Instrumental Focus | Distraction-free music to boost productivity | https://music.youtube.com/playlist?list=PLQ176FUIyIUZe607HAWNNq1z33XAOfge8 |
| Ambient Soundscapes | Calm atmospheric music for relaxation | https://music.youtube.com/playlist?list=PLQ176FUIyIUa1dA8101V-V7iesN8CgqfY |
| Coding Mix | Energetic beats to keep you in the flow | https://music.youtube.com/playlist?list=PLQ176FUIyIUYbrYf6v9y6F9wturNQf1Bf |
Simply copy any of these URLs to your playlists.txt file and run the tool to download them.
Note: These are public playlists available on YouTube Music. Please respect copyright laws when downloading music.