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

Code before:
        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:
                return self._download_json_handle(
                    f'https://10.com.au/api/v1/videos/playback/{content_id}/', content_id,
                    note='Downloading video JSON', query={'platform': 'samsung'},
                    headers=filter_dict({
                        'TP-AcceptFeature': 'v1/fw;v1/drm',
                        'Authorization': f'Bearer {self._access_token}' if self._access_token else None,
                    }))
            except ExtractorError as e:
                if not is_retry and isinstance(e.cause, HTTPError) and e.cause.status == 403:
                    if self._access_token:
                        self.report_warning('Access token has expired; refreshing')
                        self._refresh_access_token()
                        continue
                    elif not self._get_login_info()[0]:
                        self.raise_login_required('Login required to access this video', method='password')
                raise

    def _real_extract(self, url):
        content_id = self._match_id(url)

Review comment (performance):
I would do this all over to make maintenance easier
```py
    _TOKEN_CACHE_KEY = 'token_data'
```

```suggestion
        self.cache.store(self._NETRC_MACHINE, self._TOKEN_CACHE_KEY, [self._refresh_token, self._access_token])
```

Code after:
    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):
            try:
                return self._download_json_handle(
                    f'https://10.com.au/api/v1/videos/playback/{content_id}/', content_id,
                    note='Downloading video JSON', query={'platform': 'samsung'},
                    headers=filter_dict({
                        'TP-AcceptFeature': 'v1/fw;v1/drm',
                        'Authorization': f'Bearer {self._access_token}' if self._access_token else None,
                    }))
            except ExtractorError as e:
                if not is_retry and isinstance(e.cause, HTTPError) and e.cause.status == 403:
                    if self._access_token:
                        self.to_screen('Access token has expired; refreshing')
                        self._refresh_access_token()
                        continue
                    elif not self._get_login_info()[0]:
                        self.raise_login_required('Login required to access this video', method='password')
                raise

    def _real_extract(self, url):