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.2 (Latest)

  • 🐛 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.2.tar.gz (13.2 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.2-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file yt_music_extractor-1.0.2.tar.gz.

File metadata

  • Download URL: yt_music_extractor-1.0.2.tar.gz
  • Upload date:
  • Size: 13.2 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.2.tar.gz
Algorithm Hash digest
SHA256 d5d1138936654c3be72447675dd2b3144af832c033730ce2a70112e54ce3165b
MD5 10cf11111f0137f733a54cd06a890be8
BLAKE2b-256 94c24e0c532942af4ab634bf1e14c878fb443cde450e4fc179d14ae9af0edff5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for yt_music_extractor-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bd09d14c12cdc4982c5010e9dba1a466215de70f1d93af583bc6171ca4bd141a
MD5 68fc89d7433a3c1e923de5bbd149d2d9
BLAKE2b-256 b11de8e5048820603e1ebbb196b088d0eb29a727e89691f7cbbfd37827ba0720

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