feat: Add Youtube Premium detection and high qualtiy format selection #2536
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Title
Add Youtube Premium Detection and Automatic High Quality Audio Download
Description
Fixes #2501
This Pull Request introduces a new feature that automatically detects if the user's provided Youtube cookies belong to a Youtube Premium account and enables SpotDL to download the highest-quality audio formats available to Premium users.
It improves user experience by leveraging Premium access to get better audio bitrates (e.g., 160 kbps Opus) without requiring any manual configuration ensuring best possible audio experience.
For regular YouTube users, the downloader continues to function as before — downloading standard-quality audio files.
The implementation is fully backward-compatible and does not affect existing workflows for users without YouTube Premium.
Key Highlights
- Added a new utility function detect_youtube_premium() in spotdl/utils.py that:
- Integrated Premium detection logic into the YouTube audio provider flow.
- Added clear console logs:
To check if the added function is called properly
- Fully compatible with the existing downloader architecture.
Related Issue
Closes #2501
This issue discusses the need for enablign users with premium subscription to utilize their accoutn benefits and get to download their higher available qualities in premium version.
How Has This Been Tested?
Testing Environment
Test Steps
uv run python -m spotdl "<spotify_track_url>" --cookie-file tests/cookies.txt
Detection messages printed correctly:
- For Premium: "YouTube Premium detected — downloading high-quality audio."
- For Non-Premium: "Regular YouTube account — downloading standard audio."
No regression in normal downloading behavior.
Graceful fallback for invalid or expired cookies.
Example Output
`Processing query: https://open.spotify.com/track/5bQ6oDLqvw8tywmnSmwEyL?si=1f667e4c61dd455d
[YT Premium Detection] Checking formats for: https://music.youtube.com/watch?v=YALvuUpY_b0
Regular YouTube account — downloading standard audio.
Downloaded "Sachin-Jigar - Apna Bana Le": https://music.youtube.com/watch?v=YALvuUpY_b0`
Setup Instructions
To Generate cookies.txt
Install the Chrome/Firefox extension:
Get cookies.txt by editThisCookie or cookies.txt for Google Chrome.
Log in to your YouTube Premium account.
Visit https://www.youtube.com and export cookies as cookies.txt.
Move the file into your project folder (for example, tests/cookies.txt).
Use the flag in your command:
spotdl "<spotify_track_url>" --cookie-file tests/cookies.txt
Types of Changes
Checklist