A powerful Python tool that automatically downloads YouTube music mixes and intelligently splits them into individual tracks, complete with metadata, album art, and original audio quality when possible.
This application solves the common problem of wanting to save individual tracks from YouTube DJ mixes or music compilations. It identifies and extracts all chapters from a YouTube video, then processes each segment as a separate song with proper artist attribution and album art.
- Intelligent Track Splitting: Uses YouTube chapter markers to identify and split individual tracks
- Smart Audio Selection: Attempts to find and download original high-quality versions of each track
- Metadata Enrichment: Automatically extracts and embeds artist and title information
- Thumbnail Processing: Downloads, crops, and embeds album art for each track
- Redis Integration: Works as a microservice that can be controlled via Redis pub/sub
- Duplicate Detection: Prevents re-downloading tracks already in your library
- Format Support: Handles various title formats (Artist - Title, Artist | Title)
- Custom Output Locations: Supports saving to specified directories
The application consists of several key components:
- Main Processor: Orchestrates the downloading and splitting process
- Downloader: Handles YouTube video and metadata retrieval
- Track Splitter: Splits audio files and adds metadata
- Redis Communication: Enables integration with other services
- Python 3.11+ (may work with other versions)
- FFmpeg installed and available in your system PATH
- Redis (for pub/sub communication with other services)
- Required Python packages (install via
pip install -r requirements.txt):- pytubefix
- Pillow
- requests
- redis
- python-dotenv
- Clone this repository
- Install required dependencies:
pip install -r requirements.txt - Ensure FFmpeg is installed and in your PATH
- Set up Redis if you plan to use the microservice functionality
- Configure environment variables (optional)
The application can run as a microservice that listens for Redis messages:
python main.pyThis will start the application in listener mode, processing YouTube URLs received through Redis. Currently, the redis application listens on the 'mix_processing' channel.
You can also use the application directly from Python:
from main import manual_download
# Download and split a YouTube mix
manual_download('https://www.youtube.com/watch?v=YOUTUBE_ID', 'optional_output_folder')The application can be configured using environment variables in a .env file:
THUMBNAIL_FOLDER: Directory for temporary thumbnail storageOUTPUT_FOLDER: Base directory for saving output filesREDIS_PUBLISH_CHANNEL: Redis channel for publishing completion messages
- The service receives a YouTube URL via Redis or direct function call
- It downloads the video and extracts chapter information
- For each track:
- It attempts to find the original song on YouTube
- If found, it downloads the high-quality version
- Otherwise, it extracts the segment from the mix
- It adds metadata and album art
- Processed tracks are saved to the output directory
- A completion message is published to Redis (in microservice mode)
Contributions are welcome! Please feel free to submit a Pull Request.
[ ] Configurable subscriber channel for redis microservice input. Currently, the redis application listens on the 'mix_processing' channel.