A Python library for downloading videos from YouTube and YouTube Mix playlists.
pip install youtube-mix-dl==0.1.4
pip install selenium>=4.0.0 webdriver-manager>=3.8.0 yt-dlp>=2023.0.0
-
Windows:
winget install FFmpeg
-
Linux:
sudo apt update && sudo apt install ffmpeg
-
macOS:
brew install ffmpeg
-
Google Chrome/Chromium browser
-
ChromeDriver (auto-installed by webdriver-manager)
from youtube_mix_dl import YouTubeDownloader
def progress_callback(message):
print(message)
# Initialize downloader
downloader = YouTubeDownloader(
output_path="downloads",
progress_callback=progress_callback
)
# 1. Download single video
video_url = "https://www.youtube.com/watch?v=Mude7cCSs9s"
print("\nDownloading single video...")
success = downloader.download_video(video_url)
print(f"Single video download {'successful' if success else 'failed'}")
# 2. Download audio only
print("\nDownloading audio only...")
audio_options = {
'format': 'bestaudio[ext=m4a]',
'postprocessors': [{'key': 'FFmpegExtractAudio'}]
}
success = downloader.download_video(video_url, audio_options)
print(f"Audio download {'successful' if success else 'failed'}")
# 3. Download from music mix playlist
mix_url = "https://www.youtube.com/watch?v=Mude7cCSs9s&list=RDMude7cCSs9s&start_radio=1"
print("\nDownloading from music mix playlist...")
mix_downloads = downloader.download_mix(mix_url, num_videos=3)
print(f"Downloaded {mix_downloads} videos from mix")
# 4. Download from normal playlist
playlist_url = "https://www.youtube.com/playlist?list=PLPTV0NXA_ZSgsLAr8YCgCwhPIJNNtexWu"
print("\nDownloading from normal playlist...")
playlist_downloads = downloader.download_playlist(playlist_url, num_videos=3)
print(f"Downloaded {playlist_downloads} videos from playlist")
# 5. Get video information
print("\nGetting video information...")
info = downloader.get_video_info(video_url)
if info:
print(f"Video title: {info.get('title')}")
print(f"Duration: {info.get('duration')} seconds")
print(f"View count: {info.get('view_count')}")
Run the test script:
python test.py
from youtube_mix_dl import YouTubeDownloader
downloader = YouTubeDownloader(output_path="downloads")
success = downloader.download_video("https://www.youtube.com/watch?v=Mude7cCSs9s")
options = {
'format': 'bestaudio[ext=m4a]',
'postprocessors': [{'key': 'FFmpegExtractAudio'}]
}
success = downloader.download_video("https://www.youtube.com/watch?v=Mude7cCSs9s", options)
downloader = YouTubeDownloader(
output_path="downloads",
progress_callback=lambda msg: print(msg)
)
successful_downloads = downloader.download_mix(
"https://www.youtube.com/watch?v=Mude7cCSs9s&list=RDMude7cCSs9s&start_radio=1",
num_videos=5
)
successful_downloads = downloader.download_playlist(
"https://www.youtube.com/playlist?list=PLPTV0NXA_ZSgsLAr8YCgCwhPIJNNtexWu",
num_videos=5
)
- Single video and playlist downloads (music mix and normal playlists)
- Audio-only downloads
- Progress tracking with callbacks
- High-quality video/audio
- Automatic stream merging
- Error handling
- Video information retrieval
-
No Audio
- Verify FFmpeg:
ffmpeg -version
- Check PATH settings
- Verify FFmpeg:
-
ChromeDriver Issues
- Update Chrome
- Let webdriver-manager handle installation
-
Permission Issues
- Check output directory permissions
- Run with appropriate privileges
# Setup
git clone https://github.com/benny-png/YOUR_YOUTUBE_MUSIC_MIX_DOWNLOADER.git
cd YOUR_YOUTUBE_MUSIC_MIX_DOWNLOADER
python -m venv venv
source venv/bin/activate # Linux/macOS
venv\Scripts\activate # Windows
# Install dev dependencies
pip install build twine pytest black isort mypy
pip install -e .
MIT License