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

Code before:
                headers={
                    'Content-Type': 'application/json',
                }, data=json.dumps({
                    'accessToken': self._access_token,
                    'refreshToken': self._refresh_token,
                }).encode())
        except ExtractorError as e:
            if isinstance(e.cause, HTTPError) and e.cause.status == 400:
                self._refresh_token = self._access_token = None
                self.cache.store(self._NETRC_MACHINE, 'token_data', [None, None])
                self.report_warning('Refresh token has been invalidated; retrying with credentials')
                self._perform_login(*self._get_login_info())
                return
            raise
        self._access_token = refresh_data['accessToken']
        self._refresh_token = refresh_data['refreshToken']
        self.cache.store(self._NETRC_MACHINE, 'token_data', [self._refresh_token, self._access_token])

    def _perform_login(self, username, password):
        if not self._refresh_token:
            self._refresh_token, self._access_token = self.cache.load(
                self._NETRC_MACHINE, 'token_data', default=[None, None])

        if self._refresh_token and self._access_token:
            self.write_debug('Using cached refresh token')
            return
        try:
            auth_data = self._download_json(
                'https://10.com.au/api/user/auth', None, 'Logging in',
                headers={
                    'Content-Type': 'application/json',
                    'X-Network-Ten-Auth': self._generate_xnetwork_ten_auth_token(),
                    'Referer': 'https://10.com.au/',
                }, data=json.dumps({
                    'email': username,
                    'password': password,
                }).encode())
        except ExtractorError as e:
            if isinstance(e.cause, HTTPError) and e.cause.status == 400:
                raise ExtractorError('Invalid username/password', expected=True)
            raise

        self._refresh_token = auth_data['jwt']['refreshToken']
        self._access_token = auth_data['jwt']['accessToken']
        self.cache.store(self._NETRC_MACHINE, 'token_data', [self._refresh_token, self._access_token])

    def _call_playback_api(self, content_id):
        if self._access_token and self._is_jwt_expired(self._access_token):
            self._refresh_access_token()
        for is_retry in (False, True):
            try:

Review comment (bug):
```suggestion
        if self._refresh_token and self._access_token:
            self.write_debug('Using cached refresh token')
            return

```

Code after:
                'https://10.com.au/api/token/refresh', None, 'Refreshing access token',
                headers={
                    'Content-Type': 'application/json',
                }, data=json.dumps({
                    'accessToken': self._access_token,
                    'refreshToken': self._refresh_token,
                }).encode())
        except ExtractorError as e:
            if isinstance(e.cause, HTTPError) and e.cause.status == 400:
                self._refresh_token = self._access_token = None
                self.cache.store(self._NETRC_MACHINE, self._TOKEN_CACHE_KEY, [None, None])
                self.report_warning('Refresh token has been invalidated; retrying with credentials')
                self._perform_login(*self._get_login_info())
                return
            raise
        self._access_token = refresh_data['accessToken']
        self._refresh_token = refresh_data['refreshToken']
        self.cache.store(self._NETRC_MACHINE, self._TOKEN_CACHE_KEY, [self._refresh_token, self._access_token])

    def _perform_login(self, username, password):
        if not self._refresh_token:
            self._refresh_token, self._access_token = self.cache.load(
                self._NETRC_MACHINE, self._TOKEN_CACHE_KEY, default=[None, None])
        if self._refresh_token and self._access_token:
            self.write_debug('Using cached refresh token')
            return

        try:
            auth_data = self._download_json(
                'https://10.com.au/api/user/auth', None, 'Logging in',
                headers={
                    'Content-Type': 'application/json',
                    'X-Network-Ten-Auth': self._generate_xnetwork_ten_auth_token(),
                    'Referer': 'https://10.com.au/',
                }, data=json.dumps({
                    'email': username,
                    'password': password,
                }).encode())
        except ExtractorError as e:
            if isinstance(e.cause, HTTPError) and e.cause.status == 400:
                raise ExtractorError('Invalid username/password', expected=True)
            raise

        self._refresh_token = auth_data['jwt']['refreshToken']
        self._access_token = auth_data['jwt']['accessToken']
        self.cache.store(self._NETRC_MACHINE, self._TOKEN_CACHE_KEY, [self._refresh_token, self._access_token])

    def _call_playback_api(self, content_id):
        if self._access_token and self._is_jwt_expired(self._access_token):
            self._refresh_access_token()
        for is_retry in (False, True):