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

Code before:
                    self._store_client_id(client_id)
                    return
        raise ExtractorError('Unable to extract client id')

    def _download_json(self, *args, **kwargs):
        non_fatal = kwargs.get('fatal') is False
        if non_fatal:
            del kwargs['fatal']
        query = kwargs.get('query', {}).copy()
        for _ in range(2):
            query['client_id'] = self._CLIENT_ID
            kwargs['query'] = query
            try:
                return super(SoundcloudIE, self)._download_json(*args, **compat_kwargs(kwargs))
            except ExtractorError as e:
                if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:
                    self._store_client_id(None)
                    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}

Review comment (performance):
```suggestion
        self._CLIENT_ID = self._downloader.cache.load('soundcloud', 'client_id') or 'fXuVKzsVXlc6tzniWWS31etd7VHWFUuN'  # persistent `client_id`
```

for consistency

Code after:
                    self._store_client_id(client_id)
                    return
        raise ExtractorError('Unable to extract client id')

    def _download_json(self, *args, **kwargs):
        non_fatal = kwargs.get('fatal') is False
        if non_fatal:
            del kwargs['fatal']
        query = kwargs.get('query', {}).copy()
        for _ in range(2):
            query['client_id'] = self._CLIENT_ID
            kwargs['query'] = query
            try:
                return super(SoundcloudIE, self)._download_json(*args, **compat_kwargs(kwargs))
            except ExtractorError as e:
                if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:
                    self._store_client_id(None)
                    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: