coletdjnz / yt-dlp-youtube-oauth2

[OBSOLETE] Plugin that adds OAuth2 login support to yt-dlp's YouTube extractors
The Unlicense
259 stars 38 forks source link

Storing Credentials #19

Closed alimirjahani7 closed 2 months ago

alimirjahani7 commented 3 months ago

where does the code save the auth data and credentials I want to login on one device and pass the data to multiple servers to download with but I couldn't find where the oauth is saving the data

amrutadotorg commented 3 months ago

see https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/cache.py

  1. The root cache directory is determined by the _get_root_dir() method:

    • It first checks for a 'cachedir' parameter in self._ydl.params.
    • If not set, it uses the XDG_CACHE_HOME environment variable (typically ~/.cache on Unix-like systems).
    • If XDG_CACHE_HOME is not set, it defaults to ~/.cache/yt-dlp.
  2. The specific file for storing the OAuth2 token is determined by the _get_cache_fn() method:

    • It uses the section ('youtube-oauth2'), key ('token_data'), and data type ('json').
    • The key is URL-encoded for safety.
  3. The final path would be: <cache_root>/youtube-oauth2/token_data.json

So, to find the exact location on your system:

  1. Check if you've set a custom 'cachedir' parameter when initializing yt-dlp.
  2. If not, check your XDG_CACHE_HOME environment variable.
  3. If that's not set, look in ~/.cache/yt-dlp/ (on Unix-like systems) or the equivalent on Windows.

The full path would be something like: ~/.cache/yt-dlp/youtube-oauth2/token_data.json

On Windows, it might be something like: C:\Users\<YourUsername>\AppData\Local\yt-dlp\youtube-oauth2\token_data.json

To verify this, you could add a debug print statement in the store_token method of the YouTubeOAuth2Handler class:

def store_token(self, token_data):
    self.cache.store('youtube-oauth2', 'token_data', token_data)
    self._TOKEN_DATA = token_data
    # Add this line:
    print(f"Token stored at: {self.cache._get_cache_fn('youtube-oauth2', 'token_data', 'json')}")

This will print the exact file path where the token is being stored when the store_token method is called.