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

Code before:
                    self._update_client_id()
                    continue
                elif non_fatal:
                    self.report_warning(error_to_compat_str(e))
                    return False
                raise

    def _real_initialize(self):
        self._CLIENT_ID = self._downloader.cache.load('soundcloud', 'client_id') or "fXuVKzsVXlc6tzniWWS31etd7VHWFUuN"  # persistent `client_id`
        self._login()

    _USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36"
    _API_AUTH_QUERY_TEMPLATE = '?client_id=%s'
    _API_AUTH_URL_PW = 'https://api-auth.soundcloud.com/web-auth/sign-in/password%s'
    _API_VERIFY_AUTH_TOKEN = 'https://api-auth.soundcloud.com/connect/session%s'
    _access_token = None
    _HEADERS = {}
    _NETRC_MACHINE = 'soundcloud'
    _reserved_usernames = ['token', 'auth', 'oauth', 'bearer', 'authorization']

    def _login(self):
        username, password = self._get_login_info()
        if username is None:
            return

        if username in self._reserved_usernames:
            if password:
                self._access_token = password
                query = self._API_AUTH_QUERY_TEMPLATE % self._CLIENT_ID
                payload = {'session': {'access_token': self._access_token}}
                token_verification = sanitized_Request(self._API_VERIFY_AUTH_TOKEN % query, json.dumps(payload).encode('utf-8'))
                response = self._download_json(token_verification, None, note='Verifying login token...', fatal=False)
                if response is not False:
                    self._HEADERS = {'Authorization': 'OAuth ' + self._access_token}
                    self.report_login()
                else:
                    self.report_warning('Provided authorization token seems to be invalid. Continue as guest.')
            else:
                self.report_warning('No token for authentication provided!')

        '''
        def genDevId():
            def genNumBlock():
                return ''.join([str(random.randrange(10)) for i in range(6)])
            return '-'.join([genNumBlock() for i in range(4)])

        payload = {
            'client_id': self._CLIENT_ID,
            'recaptcha_pubkey': 'null',
            'recaptcha_response': 'null',
            'credentials': {

Review comment (bug):
If username is not in `oauth`, explain to the user that login is broken and only `-u oauth -p <TOKEN>` can be used

Code after:
                    self._update_client_id()
                    continue
                elif non_fatal:
                    self.report_warning(error_to_compat_str(e))
                    return False
                raise

    def _real_initialize(self):
        self._CLIENT_ID = self._downloader.cache.load('soundcloud', 'client_id') or 'fXuVKzsVXlc6tzniWWS31etd7VHWFUuN'  # persistent `client_id`
        self._login()

    _USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'
    _API_AUTH_QUERY_TEMPLATE = '?client_id=%s'
    _API_AUTH_URL_PW = 'https://api-auth.soundcloud.com/web-auth/sign-in/password%s'
    _API_VERIFY_AUTH_TOKEN = 'https://api-auth.soundcloud.com/connect/session%s'
    _access_token = None
    _HEADERS = {}
    _NETRC_MACHINE = 'soundcloud'

    def _login(self):
        username, password = self._get_login_info()
        if username is None:
            return

        if username == 'oauth' and password is not None:
            self._access_token = password
            query = self._API_AUTH_QUERY_TEMPLATE % self._CLIENT_ID
            payload = {'session': {'access_token': self._access_token}}
            token_verification = sanitized_Request(self._API_VERIFY_AUTH_TOKEN % query, json.dumps(payload).encode('utf-8'))
            response = self._download_json(token_verification, None, note='Verifying login token...', fatal=False)
            if response is not False:
                self._HEADERS = {'Authorization': 'OAuth ' + self._access_token}
                self.report_login()
            else:
                self.report_warning('Provided authorization token seems to be invalid. Continue as guest')
        elif username is not None:
            self.report_warning(
                'Login using username and password is not currently supported. '
                'Use "--user oauth --password <oauth_token>" to login using an oauth token')

        r'''
        def genDevId():
            def genNumBlock():
                return ''.join([str(random.randrange(10)) for i in range(6)])
            return '-'.join([genNumBlock() for i in range(4)])

        payload = {
            'client_id': self._CLIENT_ID,
            'recaptcha_pubkey': 'null',
            'recaptcha_response': 'null',
            'credentials': {