Skip to main content

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:

  1. Analyze the URL to determine if it's a single track or album/playlist
  2. Download the best audio quality using yt-dlp
  3. Convert to M4A format with AAC codec (256k bitrate)
  4. Process cover art (crop to square, resize to 500x500px)
  5. Embed metadata and cover art into audio files
  6. Organize files into appropriate folders
  7. 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

  1. Missing audio files: Check if the URL is accessible and not geo-blocked
  2. Conversion errors: Ensure FFmpeg is installed and accessible
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yt_music_extractor-1.0.3.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yt_music_extractor-1.0.3-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

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

Hashes for yt_music_extractor-1.0.3.tar.gz
Algorithm Hash digest
SHA256 b94392812a4202414ae69ea8f87784831f928037151483024c72af1d5240cf57
MD5 f11e19844ba61f43963f130cb8a866f4
BLAKE2b-256 bcef25f917f99aaf914fc084ab93701ae995a087e642e6f3aa9660f26a94ac32

See more details on using hashes here.

File details

Details for the file yt_music_extractor-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for yt_music_extractor-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 39d500373b092f062aa2472960f5a5cd82936b136f3bc279a1f3fea6d5f8caf0
MD5 2e5f77bb3a8228f061021bf591a1accc
BLAKE2b-256 4732dfa362632ac355263206a6c256cb469c85a27eb7c5ec566d8cb207555a1f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page