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

Code before:
            'https://auth-id.nfl.com/accounts.getAccountInfo', video_id,
            note='Downloading account info', data=urlencode_postdata({
                'include': 'profile,data',
                'lang': 'en',
                'APIKey': self._API_KEY,
                'sdk': 'js_latest',
                'login_token': login_token,
                'authMode': 'cookie',
                'pageURL': url,
                'sdkBuild': traverse_obj(cookies, (
                    'gig_canary_ver', {lambda x: x.value.partition('-')[0]}), default='13642'),
                'format': 'json',
            }), headers={'Content-Type': 'application/x-www-form-urlencoded'})

        self._ACCOUNT_INFO = traverse_obj(account, {
            'uid': 'UID',
            'uidSignature': 'UIDSignature',
            'signatureTimestamp': 'signatureTimestamp'
        })

    def _get_auth_token(self, url, video_id):
        if not self._ACCOUNT_INFO:
            self._get_account_info(url, video_id)

        token = self._download_json(
            'https://api.nfl.com/identity/v3/token%s' % ('/refresh' if self._ACCOUNT_INFO['refreshToken'] else ''),
            video_id, headers={'Content-Type': 'application/json'}, note='Downloading access token',
            data=json.dumps({**self._CLIENT_DATA, **self._ACCOUNT_INFO}, separators=(',', ':')).encode())

        self._TOKEN = token['accessToken']
        self._TOKEN_EXPIRY = token['expiresIn']
        self._ACCOUNT_INFO['refreshToken'] = token['refreshToken']

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

        if not self._API_KEY:
            webpage = self._download_webpage(url, slug)
            self._API_KEY = self._search_regex(
                r'window\.gigyaApiKey=["\'](\w+)["\'];', webpage, 'API key')

        if not self._TOKEN or self._TOKEN_EXPIRY <= int(time.time()):
            self._get_auth_token(url, slug)

        video_id = self._download_json(
            f'https://api.nfl.com/content/v1/videos/episodes/{slug}', slug, headers={
                'Authorization': f'Bearer {self._TOKEN}',
            })['mcpPlaybackId']

        return self.url_result(f'{self._ANVATO_PREFIX}{video_id}', AnvatoIE, video_id)


Review comment (suggestion):
```suggestion
            'https://api.nfl.com/identity/v3/token%s' % (
                '/refresh' if self._ACCOUNT_INFO.get('refreshToken') else ''),
```

Code after:
            self.raise_login_required()

        account = self._download_json(
            'https://auth-id.nfl.com/accounts.getAccountInfo', video_id,
            note='Downloading account info', data=urlencode_postdata({
                'include': 'profile,data',
                'lang': 'en',
                'APIKey': self._API_KEY,
                'sdk': 'js_latest',
                'login_token': login_token,
                'authMode': 'cookie',
                'pageURL': url,
                'sdkBuild': traverse_obj(cookies, (
                    'gig_canary_ver', {lambda x: x.value.partition('-')[0]}), default='13642'),
                'format': 'json',
            }), headers={'Content-Type': 'application/x-www-form-urlencoded'})

        self._ACCOUNT_INFO = traverse_obj(account, {
            'signatureTimestamp': 'signatureTimestamp',
            'uid': 'UID',
            'uidSignature': 'UIDSignature',
        })

        if len(self._ACCOUNT_INFO) != 3:
            raise ExtractorError('Failed to retrieve account info with provided cookies', expected=True)

    def _get_auth_token(self, url, video_id):
        if not self._ACCOUNT_INFO:
            self._get_account_info(url, video_id)

        token = self._download_json(
            'https://api.nfl.com/identity/v3/token%s' % (
                '/refresh' if self._ACCOUNT_INFO.get('refreshToken') else ''),
            video_id, headers={'Content-Type': 'application/json'}, note='Downloading access token',
            data=json.dumps({**self._CLIENT_DATA, **self._ACCOUNT_INFO}, separators=(',', ':')).encode())

        self._TOKEN = token['accessToken']
        self._TOKEN_EXPIRY = token['expiresIn']
        self._ACCOUNT_INFO['refreshToken'] = token['refreshToken']

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

        if not self._API_KEY:
            webpage = self._download_webpage(url, slug, fatal=False) or ''
            self._API_KEY = self._search_regex(
                r'window\.gigyaApiKey=["\'](\w+)["\'];', webpage, 'API key',
                default='3_Qa8TkWpIB8ESCBT8tY2TukbVKgO5F6BJVc7N1oComdwFzI7H2L9NOWdm11i_BY9f')

        if not self._TOKEN or self._TOKEN_EXPIRY <= int(time.time()):
            self._get_auth_token(url, slug)