Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/youtube.py (Python)

Code before:
        cookies = self._get_cookies('https://www.youtube.com/')
        pref_cookie = cookies.get('PREF')
        pref = {}
        if pref_cookie:
            try:
                pref = dict(urllib.parse.parse_qsl(pref_cookie.value))
            except ValueError:
                self.report_warning('Failed to parse user PREF cookie' + bug_reports_message())
        pref.update({'hl': self._preferred_lang or 'en', 'tz': 'UTC'})
        self._set_cookie('.youtube.com', name='PREF', value=urllib.parse.urlencode(pref))

    def _real_initialize(self):
        self._initialize_pref()
        self._initialize_consent()
        self._check_login_required()

    def _perform_login(self, username, password):
        auth_type, sep, user = (username or '').partition('+')

        if user and sep != '+':
            raise ExtractorError('Invalid username format. Expected "AUTH_TYPE+USER".', expected=True)

        if auth_type != 'oauth':
            raise ExtractorError(
                'Login using username and password is not supported. '
                'Use "--username oauth[+USER] --password \'\'" to login using an oauth, '
                f'or else {self._login_hint(method="cookies")}', expected=True)

        self._initialize_oauth(user, password)

    _OAUTH_USER = None
    _OAUTH_ACCESS_TOKEN_CACHE = {}

    # YouTube TV (TVHTML5) client
    _OAUTH_CLIENT_ID = '861556708454-d6dlm3lh05idd8npek18k6be8ba3oc68.apps.googleusercontent.com'
    _OAUTH_CLIENT_SECRET = 'SboVhoG9s0rNafixCSGGKXAT'
    _OAUTH_SCOPE = 'http://gdata.youtube.com https://www.googleapis.com/auth/youtube'

    def _set_oauth_info(self, token_response, user):

        YoutubeBaseInfoExtractor._OAUTH_ACCESS_TOKEN_CACHE.setdefault(user, {}).update({
            'access_token': token_response['access_token'],
            'token_type': token_response['token_type'],
            'expiry': time_seconds(
                seconds=traverse_obj(token_response, ('expires_in', {float_or_none}), default=300) - 10),
        })

        refresh_token = traverse_obj(token_response, 'refresh_token', {str})
        if refresh_token:
            self.cache.store(self._NETRC_MACHINE, f'oauth_refresh_token_{user}', refresh_token)
            YoutubeBaseInfoExtractor._OAUTH_ACCESS_TOKEN_CACHE[user]['refresh_token'] = refresh_token

Review comment (security):
This suggestion might be problematic for windows since `''` will be a literal. How about something like this instead:
```suggestion
                'Use  --username oauth[+USER] --password ""  to login using an oauth, '
```

Code after:
        pref_cookie = cookies.get('PREF')
        pref = {}
        if pref_cookie:
            try:
                pref = dict(urllib.parse.parse_qsl(pref_cookie.value))
            except ValueError:
                self.report_warning('Failed to parse user PREF cookie' + bug_reports_message())
        pref.update({'hl': self._preferred_lang or 'en', 'tz': 'UTC'})
        self._set_cookie('.youtube.com', name='PREF', value=urllib.parse.urlencode(pref))

    def _real_initialize(self):
        self._initialize_pref()
        self._initialize_consent()
        self._check_login_required()

    def _perform_login(self, username, password):
        auth_type, _, user = (username or '').partition('+')

        if auth_type != 'oauth':
            raise ExtractorError(self._youtube_login_hint, expected=True)

        self._initialize_oauth(user, password)

    '''
    OAuth 2.0 Device Authorization Grant flow, used by the YouTube TV client (youtube.com/tv).

    For more information regarding OAuth 2.0 and the Device Authorization Grant flow in general, see:
    - https://developers.google.com/identity/protocols/oauth2/limited-input-device
    - https://accounts.google.com/.well-known/openid-configuration
    - https://www.rfc-editor.org/rfc/rfc8628
    - https://www.rfc-editor.org/rfc/rfc6749

    Note: The official client appears to use a proxied version of the oauth2 endpoints on youtube.com/o/oauth2,
    which applies some modifications to the response (such as returning errors as 200 OK).
    Since the client works with the standard API, we will use that as it is well-documented.
    '''

    _OAUTH_PROFILE = None
    _OAUTH_ACCESS_TOKEN_CACHE = {}
    _OAUTH_DISPLAY_ID = 'oauth'

    # YouTube TV (TVHTML5) client. You can find these at youtube.com/tv
    _OAUTH_CLIENT_ID = '861556708454-d6dlm3lh05idd8npek18k6be8ba3oc68.apps.googleusercontent.com'
    _OAUTH_CLIENT_SECRET = 'SboVhoG9s0rNafixCSGGKXAT'
    _OAUTH_SCOPE = 'http://gdata.youtube.com https://www.googleapis.com/auth/youtube-paid-content'

    # From https://accounts.google.com/.well-known/openid-configuration
    # Technically, these should be fetched dynamically and not hard-coded.
    # However, as these endpoints rarely change, we can risk saving an extra request for every invocation.
    _OAUTH_DEVICE_AUTHORIZATION_ENDPOINT = 'https://oauth2.googleapis.com/device/code'
    _OAUTH_TOKEN_ENDPOINT = 'https://oauth2.googleapis.com/token'