Skip to content

Conversation

KingVibhor
Copy link

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:

  1. Accepts a user-provided cookies.txt path.
  2. Uses yt_dlp to analyze available formats for the requested video.
  3. Detects access to Premium-only formats and returns a boolean flag.

- Integrated Premium detection logic into the YouTube audio provider flow.

- Added clear console logs:

  1. "YouTube Premium detected — downloading high-quality audio."
  2. "Regular YouTube account — downloading standard audio."
  3. "[YT Premium Detection] Checking formats for: (corresponding youtube link)"
    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

  • OS: Windows 11
  • Python: 3.14
  • Virtual Environment: uv + .venv

Test Steps

  1. Created a valid 'cookies.txt' using browser extension(see below for steps)
  2. Ran:
    uv run python -m spotdl "<spotify_track_url>" --cookie-file tests/cookies.txt
  3. Verfiied:
  • 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.

  1. Could not test for premium version as I don't have Youtube Premium. It would be of great help if you could help me with that. Maintainers or contributors with Premium access are requested to help validate this scenario.

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

  1. Install the Chrome/Firefox extension:
    Get cookies.txt by editThisCookie or cookies.txt for Google Chrome.

  2. Log in to your YouTube Premium account.

  3. Visit https://www.youtube.com and export cookies as cookies.txt.

  4. Move the file into your project folder (for example, tests/cookies.txt).

  5. Use the flag in your command:
    spotdl "<spotify_track_url>" --cookie-file tests/cookies.txt

Types of Changes

  • New feature (non-breaking change which adds functionality)

Checklist

  • My code follows the code style of this project
  • I have added necessary documentation for setup and usage
  • I have tested the feature thoroughly with non-premium cookies
  • I have read the CONTRIBUTING document
  • All new and existing tests passed
  • Verified that non-Premium users remain unaffected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inform the user if YouTube Premium cookies are detected

1 participant