Download music from YouTube with proper metadata and album art, featuring parallel processing
Project description
YouTube Music Extractor
A Python tool to download music from YouTube/YouTube Music with proper metadata and album art, featuring parallel processing for albums and playlists.
Features
- ๐ต Download music from YouTube or YouTube Music URLs
- ๐ Support for both single tracks and full albums/playlists
- ๐ Parallel processing for faster album downloads
- ๐ง Convert to high-quality M4A format with 256k bitrate
- ๐ท๏ธ Extract and embed metadata (title, artist, album, genre, track numbers)
- ๐ผ๏ธ Process album artwork to perfect 1:1 aspect ratio (500x500px)
- ๐ Organized folder structure for albums and single tracks
- ๐งน Automatic cleanup of temporary files
- ๐ฎ Optimize for VLC and other media players
Requirements
- Python 3.7+
- Dependencies listed in
requirements.txt
Installation
Option 1: Clone and Install
git clone https://github.com/Captain-Vikram/YTMusic_To_M4A
cd YTMusic_To_M4A
Option 2: Install as Package
pip install -e .
Set up Virtual Environment (Recommended)
python -m venv .venv
# Windows
.venv\Scripts\activate
# macOS/Linux
source .venv/bin/activate
Install Dependencies
pip install -r requirements.txt
Usage
Basic Usage
python main.py
As Installed Package
yt-music-extractor
The script will prompt you for a YouTube/YouTube Music URL and then:
- Analyze the URL to determine if it's a single track or album/playlist
- Download the best audio quality using yt-dlp
- Convert to M4A format with AAC codec (256k bitrate)
- Process cover art (crop to square, resize to 500x500px)
- Embed metadata and cover art into audio files
- Organize files into appropriate folders
- Clean up temporary files
Examples
Single Track
Enter the YouTube URL: https://music.youtube.com/watch?v=dQw4w9WgXcQ
Creates: Single - Song Title/Song Title.m4a
Album/Playlist
Enter the YouTube URL: https://music.youtube.com/playlist?list=OLAK5uy_xyz
Creates: Album Title/Track 1.m4a, Album Title/Track 2.m4a, etc.
Features in Detail
Parallel Processing
- Albums and playlists are processed using ThreadPoolExecutor
- Up to 4 concurrent downloads (configurable in
config.py) - Real-time progress tracking
Metadata Handling
- Title: Song title from YouTube
- Artist: Channel name or extracted artist
- Album: Playlist/album title or song title for singles
- Genre: "YouTube Music" (default)
- Track Numbers: Automatic numbering for album tracks
- Cover Art: Embedded as MP4Cover format
File Organization
Project Root/
โโโ Album Title/
โ โโโ Track 1.m4a
โ โโโ Track 2.m4a
โ โโโ cover.jpg
โ โโโ Track 1.jpg (external cover for VLC)
โโโ Single - Song Title/
โโโ Song Title.m4a
โโโ cover.jpg
Image Processing
- Automatically crops images to 1:1 aspect ratio
- Resizes to 500x500px for optimal compatibility
- Converts to JPEG format (95% quality)
- Creates both embedded and external cover art
Configuration
Modify settings in config.py:
# Audio quality
AUDIO_BITRATE = "256k"
# Image processing
IMAGE_TARGET_SIZE = 500
IMAGE_QUALITY = 95
# Threading
MAX_WORKERS = 4
Troubleshooting
Common Issues
- Missing audio files: Check if the URL is accessible and not geo-blocked
- Conversion errors: Ensure FFmpeg is installed and accessible
- Metadata errors: Some files may not support M4A metadata format
Debug Mode
Add verbose logging by modifying the yt-dlp options in the script.
Dependencies
- yt-dlp: YouTube download functionality
- moviepy: Audio conversion and processing
- mutagen: Audio metadata handling
- Pillow: Image processing and manipulation
- requests: HTTP requests for thumbnail downloads
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
Acknowledgments
- yt-dlp for robust YouTube download functionality
- MoviePy for audio conversion capabilities
- Mutagen for comprehensive metadata handling
- Pillow for advanced image processing
Changelog
v1.0.3 (Latest)
โจ Major Enhancements
- Quality Detection: Real-time audio quality verification and reporting
- Smart File Handling: Robust filename matching prevents conversion errors
- Parallel Processing: Faster album downloads with concurrent track processing
- VLC Optimization: Perfect album artwork and external cover files
๐ง Technical Improvements
- Enhanced M4A file detection (no unnecessary re-conversion)
- Improved metadata embedding with better error handling
- Smart cleanup system that preserves project files
- Cross-platform filename sanitization
- Optional format analysis before download
๐ต Audio Quality Features
- Support for up to 320kbps AAC downloads
- Intelligent format selection prioritizes highest quality
- Real-time quality reporting during download
- Optional pre-download format analysis
๐ Better Organization
- Clean folder structure for singles and albums
- Automatic cleanup preserves only final M4A files
- External cover art files for perfect VLC compatibility
- Smart handling of existing M4A files (no re-processing)
๐ Bug Fixes
- Fixed filename mismatch issues during conversion
- Resolved metadata embedding errors
- Improved error handling for network issues
- Better handling of special characters in filenames
v1.0.2
- ๐ Fixed bug in metadata handling
- ๐ Updated documentation
v1.0.1
- ๐ Initial PyPI release
- ๐ฆ Fixed packaging issues
- All features from v1.0.0 included
v1.0.0
- ๐ Added parallel processing for albums and playlists
- ๐ Improved file organization with dedicated folders
- ๐ผ๏ธ Enhanced image processing with 1:1 aspect ratio cropping
- ๐งน Automatic cleanup of temporary files
- ๐ Better error handling and progress tracking
- ๐ฎ VLC-optimized output with external cover art files
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 yt_music_extractor-1.0.3.tar.gz.
File metadata
- Download URL: yt_music_extractor-1.0.3.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b94392812a4202414ae69ea8f87784831f928037151483024c72af1d5240cf57
|
|
| MD5 |
f11e19844ba61f43963f130cb8a866f4
|
|
| BLAKE2b-256 |
bcef25f917f99aaf914fc084ab93701ae995a087e642e6f3aa9660f26a94ac32
|
File details
Details for the file yt_music_extractor-1.0.3-py3-none-any.whl.
File metadata
- Download URL: yt_music_extractor-1.0.3-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39d500373b092f062aa2472960f5a5cd82936b136f3bc279a1f3fea6d5f8caf0
|
|
| MD5 |
2e5f77bb3a8228f061021bf591a1accc
|
|
| BLAKE2b-256 |
4732dfa362632ac355263206a6c256cb469c85a27eb7c5ec566d8cb207555a1f
|