A powerful command-line music downloader with automatic album artwork and intelligent organization
Project description
CLI Music Downloader
๐ต A powerful command-line music downloader with automatic album artwork and intelligent organization
By The Way! This is my first major software release. If you enjoyed this tool please consider donating via the following link:
โจ Features
- ๐ต High-quality music downloads from YouTube with optimal audio extraction
- ๐จ Automatic album artwork fetching from iTunes API and Google Images
- ๐ Smart organization by artist in
~/Music/<Artist>/<Song>.mp3 - ๐ท๏ธ Enhanced metadata system with MusicBrainz, Last.fm, and Discogs integration
- ๐ผ MusicBrainz integration for comprehensive music metadata
- ๐ง Audio fingerprinting with Shazam for accurate song identification
- ๐ Automatic lyrics fetching and embedding from Genius API
- ๐ง Warp Terminal integration with custom workflows
- ๐ ๏ธ Robust error handling and fallback mechanisms
- ๐ฑ Multiple image formats support (JPEG, PNG, WebP)
- ๐ Intelligent search with artist/track parsing
- ๐ Batch processing for existing music libraries
- โ๏ธ Flexible metadata sources with a priority system
๐ Quick Start
๐ฏ Simple Installation (Recommended)
Install with a single command using pip:
# Install from PyPI (once published)
pip install CLI-Music-Downloader
# Or install directly from GitHub
pip install git+https://github.com/jordolang/CLI-Music-Downloader.git
# Install with all optional features
pip install CLI-Music-Downloader[all]
Start downloading immediately:
# Download with comprehensive metadata and album art
cli-music-downloader download "The Beatles Hey Jude"
download-music "Taylor Swift Shake It Off"
download-music "Queen Bohemian Rhapsody"
Docker Setup (Alternative)
Easy deployment with environment-specific configuration:
# Clone and setup
git clone https://github.com/yourusername/CLI-Music-Downloader.git
cd CLI-Music-Downloader
# Development setup
cp .env.example .env
# Edit .env with your configuration
docker-compose up -d
# Download music
docker-compose exec cli-music-downloader download_music "The Beatles Hey Jude"
Development Installation
One-command music downloads with everything included:
# Download with lyrics, album art, and metadata automatically
download_music "Taylor Swift Shake It Off"
download_music "The Beatles Hey Jude"
download_music "Queen Bohemian Rhapsody"
โ Production Ready Features
๐ฏ What Each Download Includes:
- โ High-quality audio from YouTube (typically 128-320 kbps)
- โ Official album artwork from iTunes API (600x600px)
- โ Complete lyrics from Genius API embedded in ID3 tags
- โ Comprehensive metadata (artist, title, album, genre, year)
- โ
Perfect file organization:
~/Music/Artist/Song.mp3 - โ Smart artist parsing (handles "Ed Sheeran", "Taylor Swift", etc.)
- โ Graceful error handling with fallback mechanisms
๐งช Tested Production Examples:
- RANI - Amen: 209s audio, 66.4KB artwork, 1,395 chars lyrics โ
- Taylor Swift - Shake It Off: 242s audio, 51.5KB artwork, 3,124 chars lyrics โ
- Ed Sheeran - Perfect: Full metadata, lyrics, and artwork โ
Prerequisites
- macOS (tested on macOS Monterey+)
- Python 3.8+ with pip
- Homebrew (for system dependencies)
- Warp Terminal (optional, for workflow integration)
Development Setup
- Create virtual environment:
python3 -m venv .venv - Activate virtual environment:
source .venv/bin/activate - Install dependencies:
pip install -r requirements.txt - Configure Genius API for lyrics:
export GENIUS_API_KEY="your_api_key_here"
๐ API Configuration
To enable lyrics functionality, obtain a Genius API key:
- Visit Genius API
- Create an account and generate a Client Access Token
- Add to your shell profile:
echo 'export GENIUS_API_KEY="your_token_here"' >> ~/.zshrc source ~/.zshrc
System Dependencies
The downloader uses several metadata management tools that need to be installed via Homebrew:
brew install exiftool id3v2
- exiftool: Advanced metadata extraction and manipulation
- id3v2: Command-line ID3 tag editor for MP3 files
Installation
-
Clone the repository:
git clone https://github.com/yourusername/CLI-Music-Downloader.git cd CLI-Music-Downloader
-
Run the installation script:
chmod +x scripts/install.sh ./scripts/install.sh
-
Or install manually:
# Install core dependencies pip install instantmusic eyed3 requests # Install enhanced metadata dependencies pip install musicbrainzngs mutagen lyricsgenius shazamio pylast discogs-client # Copy scripts to local bin cp bin/download_music ~/.local/bin/ cp bin/fixalbumart_improved ~/.local/bin/ cp scripts/download_music.py ~/.local/bin/ cp batch_metadata.py ~/.local/bin/ chmod +x ~/.local/bin/download_music chmod +x ~/.local/bin/fixalbumart_improved chmod +x ~/.local/bin/download_music.py chmod +x ~/.local/bin/batch_metadata.py # Install Warp workflow (optional) mkdir -p ~/.config/warp/workflows cp workflows/download_music.yaml ~/.config/warp/workflows/
๐ต Usage
Basic Downloads
# Download a song with enhanced metadata
download_music "The Beatles Hey Jude"
download_music "Pink Floyd - Comfortably Numb"
download_music "Queen Bohemian Rhapsody"
Enhanced Metadata Features
# Download with full metadata from MusicBrainz
download_music "https://example.com/song" --metadata-source musicbrainz
# Download with specific metadata source
download_music "Adele Rolling in the Deep" --metadata-source all
# Force metadata refresh for existing files
download_music "Artist Song" --force-metadata
# Skip metadata enhancement entirely
download_music "Artist Song" --skip-metadata
# Provide explicit artist and title hints
download_music "search term" --artist "The Beatles" --title "Hey Jude"
Batch Metadata Processing
# Fix metadata for existing files
batch_metadata.py --fix "Adele - Rolling in the Deep.mp3"
# Scan entire music library for metadata issues
batch_metadata.py --scan ~/Music
# View detailed metadata report
batch_metadata.py --report --detailed
# Dry run to see what would be fixed
batch_metadata.py --fix ~/Music/Artist --dry-run
Warp Terminal Workflow
- Open Warp Terminal
- Press
Cmd+Shift+Rto open workflow picker - Type "Download Music" and select the workflow
- Enter your search query (e.g., "Radiohead Creep")
- Press Enter and enjoy! ๐
Album Art Fixer (Standalone)
# Fix album art for existing files
fixalbumart_improved "/path/to/song.mp3" "Artist Name" "Track Name"
# Auto-detect from filename (works with "Artist - Track.mp3" format)
fixalbumart_improved "/path/to/Artist - Track.mp3"
๐ณ Docker Environment Configuration
Environment Variables
The Docker setup supports comprehensive environment configuration for different deployment scenarios:
| Variable | Description | Default | Example |
|---|---|---|---|
MUSIC_PATH |
Music directory path | ~/Music |
/data/music |
CONFIG_PATH |
Configuration directory | ~/.config/cli-music-downloader |
/data/config |
DOWNLOAD_QUALITY |
Audio quality | best |
320, 256, 128 |
METADATA_SOURCE |
Metadata source | all |
musicbrainz, lastfm |
GENIUS_API_KEY |
Genius API for lyrics | - | your-api-key |
Deployment Examples
# Development with custom music directory
MUSIC_PATH=~/MyMusic docker-compose up -d
# Production with high-quality downloads
DOWNLOAD_QUALITY=best MUSIC_PATH=/data/music docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
# Custom metadata source
METADATA_SOURCE=musicbrainz docker-compose up -d
Configuration Files
.env.example: Template for environment variables.env.development: Development-specific settings.env.production: Production-optimized settingsdocker-compose.yml: Base Docker configurationdocker-compose.prod.yml: Production overrides
For complete configuration details, see docs/ENVIRONMENT_CONFIGURATION.md.
๐ Project Structure
CLI-Music-Downloader/
โโโ bin/
โ โโโ download_music # Main download script
โ โโโ fixalbumart_improved # Album art processor
โโโ workflows/
โ โโโ download_music.yaml # Warp Terminal workflow
โโโ scripts/
โ โโโ install.sh # Installation script
โ โโโ uninstall.sh # Uninstallation script
โ โโโ download_music.py # Enhanced Python downloader
โ โโโ lyrics_metadata.py # Lyrics and metadata handler
โ โโโ metadata_manager.py # Multi-source metadata manager
โโโ batch_metadata.py # Batch metadata processor
โโโ examples/
โ โโโ sample_usage.md # Usage examples
โโโ docs/
โ โโโ TROUBLESHOOTING.md # Common issues and solutions
โ โโโ API.md # Technical documentation
โ โโโ ENVIRONMENT_CONFIGURATION.md # Environment config guide
โโโ docker-compose.yml # Docker configuration
โโโ docker-compose.prod.yml # Production overrides
โโโ Dockerfile # Container definition
โโโ .env.example # Environment template
โโโ .env.development # Development settings
โโโ .env.production # Production settings
โโโ README.md # This file
โโโ LICENSE # MIT License
โโโ requirements.txt # Python dependencies
๐ง How It Works
- Download Audio: Uses
instantmusic(powered by yt-dlp) to download high-quality audio from YouTube - Organize Files: Automatically creates artist folders and moves files to
~/Music/<Artist>/ - Fetch Album Art:
- Primary: iTunes API for high-quality official artwork
- Fallback: Google Images search with quality filtering
- Embed Metadata: Uses
eyed3to properly tag files and embed album artwork - Error Recovery: Graceful handling of network issues and missing artwork
๐ Metadata Sources and Priorities
The CLI Music Downloader uses multiple metadata sources to ensure comprehensive and accurate music information:
1. MusicBrainz (Primary Source)
- Data Retrieved: Artist, album, year, track numbers, genre, MusicBrainz IDs
- Features: Release group analysis, artist credit handling
- Confidence: High (90%)
- Use Case: Primary source for all metadata lookups
2. Shazam (Audio Fingerprinting)
- Data Retrieved: Artist, title, album (when available)
- Features: Audio identification from downloaded file
- Confidence: Medium-High (70%)
- Use Case: When filename parsing fails or metadata is missing
3. Genius (Lyrics)
- Data Retrieved: Song lyrics
- Features: Clean lyrics processing, embedded in ID3 tags
- Integration: Uses existing LyricsMetadataHandler
- Use Case: Lyrics enhancement for downloaded tracks
4. Last.fm (Genre and Artist Info)
- Data Retrieved: Genre tags, artist information, album details
- Features: Community-driven tagging, extensive database
- Confidence: Medium (60%)
- Use Case: Fallback for genre and additional artist information
5. Discogs (Release Information)
- Data Retrieved: Detailed release info, catalog numbers, formats
- Features: Comprehensive release database
- Confidence: Medium (60%)
- Use Case: Specialized release information and catalog data
Source Selection Strategy
The system automatically selects the best source based on:
- Data availability and completeness
- Source reliability and confidence scores
- User preferences (via
--metadata-sourceflag) - Fallback hierarchy when primary sources fail
๐ Troubleshooting Common Metadata Issues
Missing Metadata
Symptoms: Downloaded files have empty or incomplete metadata fields
Solutions:
# Force metadata refresh
download_music "Artist Song" --force-metadata
# Try different metadata source
download_music "Artist Song" --metadata-source musicbrainz
# Provide explicit artist/title hints
download_music "search term" --artist "Artist" --title "Song"
Incorrect Metadata
Symptoms: Wrong artist, title, album, or other metadata fields
Solutions:
# Force metadata refresh with specific source
batch_metadata.py --fix "path/to/file.mp3" --dry-run
# Use batch processor to fix multiple files
batch_metadata.py --fix ~/Music/Artist --verbose
API Rate Limiting
Symptoms: "Rate limit exceeded" or slow metadata fetching
Solutions:
- Wait before retrying requests
- Use batch processing with delays:
batch_metadata.py --fix ~/Music - Check API key configurations for Last.fm and Discogs
Audio Fingerprinting Failures
Symptoms: Shazam identification not working
Solutions:
- Ensure audio file is not corrupted
- Try with different metadata source:
--metadata-source musicbrainz - Check file format compatibility (MP3, FLAC, M4A supported)
Network Connectivity Issues
Symptoms: Metadata lookup timeouts or connection errors
Solutions:
# Skip metadata if network issues persist
download_music "Artist Song" --skip-metadata
# Run metadata enhancement later
batch_metadata.py --fix ~/Music/newly_downloaded
Configuration Issues
Symptoms: Metadata sources not working despite correct setup
Solutions:
# View current configuration
batch_metadata.py --config
# Set API keys via environment variables
export GENIUS_API_KEY="your_key_here"
export LASTFM_API_KEY="your_key_here"
export DISCOGS_USER_TOKEN="your_token_here"
For extensive troubleshooting tips, visit the docs/TROUBLESHOOTING.md.
๐จ Album Art Sources
iTunes API (Primary)
- โ High-quality official artwork (600x600px)
- โ Reliable metadata
- โ Fast response times
- โ No rate limiting for reasonable usage
Google Images (Fallback)
- โ Extensive coverage
- โ Quality filtering (1KB-5MB)
- โ Multiple format support
- โ ๏ธ May require user-agent headers
๐ ๏ธ Dependencies
Core Dependencies
- instantmusic: Core music downloading
- eyed3: ID3 tag manipulation
- requests: HTTP requests for album art
- yt-dlp: YouTube audio extraction (dependency of instantmusic)
Enhanced Metadata Dependencies
- musicbrainzngs: MusicBrainz API client
- mutagen: Advanced audio metadata handling
- lyricsgenius: Genius API for lyrics
- shazamio: Audio fingerprinting and identification
- pylast: Last.fm API client
- discogs-client: Discogs API client
๐ฑ Output Structure
Downloaded music is organized as:
~/Music/
โโโ Coldplay/
โ โโโ Yellow (Official Video).mp3
โโโ The Beatles/
โ โโโ Hey Jude.mp3
โโโ Queen/
โ โโโ Bohemian Rhapsody (Official Video).mp3
โโโ ...
Each file includes:
- ๐ท๏ธ Comprehensive ID3 tags: artist, title, album, year, track number, genre
- ๐จ High-quality embedded album artwork (up to 600x600px)
- ๐ต Optimal audio quality (typically 128-320 kbps)
- ๐ Embedded lyrics (when available from Genius API)
- ๐ MusicBrainz IDs for precise music identification
- ๐ Validation metadata ensuring data quality
๐ Troubleshooting
Common Issues
"Command not found: download_music"
# Ensure ~/.local/bin is in your PATH
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
"Album art processing failed"
- Network connectivity issues
- Try running
fixalbumart_improvedmanually on the file - Check if Python dependencies are properly installed
"No such file or directory"
- Run the installation script:
./scripts/install.sh - Verify all dependencies are installed
See docs/TROUBLESHOOTING.md for more detailed solutions.
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- instantmusic for the core downloading functionality
- yt-dlp for reliable YouTube audio extraction
- eyed3 for ID3 tag manipulation
- Apple iTunes API for high-quality album artwork
- The open-source community for inspiration and tools
โญ Star History
If this project helped you, please consider giving it a star! โญ
Made with โค๏ธ for music lovers who appreciate good tooling
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cli_music_downloader-1.0.0.tar.gz.
File metadata
- Download URL: cli_music_downloader-1.0.0.tar.gz
- Upload date:
- Size: 96.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f465a9fb9898ed306a5e655b0d1376ca691cfa9245f1199d7bc0708c4a51135f
|
|
| MD5 |
2a8224bae5b3b42b9f6ce499fd7d6cda
|
|
| BLAKE2b-256 |
01641dc52f9e0c602ea96c163a7243a66fe26f99ae45d93d0f1d8c4ea3d5eb1f
|
File details
Details for the file cli_music_downloader-1.0.0-py3-none-any.whl.
File metadata
- Download URL: cli_music_downloader-1.0.0-py3-none-any.whl
- Upload date:
- Size: 35.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc43db2aa03731bceb547d209134c6f8574717a278d2d9675afb2c0f2c614090
|
|
| MD5 |
9e7cdd6762b27705a59273fbe381e1aa
|
|
| BLAKE2b-256 |
65939d15743301a258bdb85b1476fc9175fc0260952f7e3dc2b121cb9dbb5a70
|