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

Code before:
            headers={'X-Domain-Id': 100}, note='Fetching token info')
        token_type = reroute.get('token_type') or 'Bearer'
        auth_token = f'{token_type} {reroute["access_token"]}'
        response = self._download_json(
            'https://api.nfl.com/v3/shield/', mcp_id, data=json.dumps({
                'query': '''{
  viewer {
    mediaToken(anvack: "%s", id: %s) {
      token
    }
  }
}''' % (anvack, mcp_id),
            }).encode(), headers={
                'Authorization': auth_token,
                'Content-Type': 'application/json',
            }, note='Fetching NFL API token')
        return traverse_obj(response, ('data', 'viewer', 'mediaToken', 'token'))

    _TOKEN_GENERATORS = {
        'GXvEgwyJeWem8KCYXfeoHWknwP48Mboj': _generate_nfl_token,
    }

    def _server_time(self, access_key, video_id):
        return int_or_none(self._download_json(
            f'{self._API_BASE_URL}/server_time', video_id, query={'anvack': access_key},
            note='Fetching server time', fatal=False).get('server_time')) or int(time.time())

    def _get_video_json(self, access_key, video_id, extracted_token):
        # See et() in anvplayer.min.js, which is an alias of getVideoJSON()
        video_data_url = f'{self._API_BASE_URL}/mcp/video/{video_id}?anvack={access_key}'
        server_time = self._server_time(access_key, video_id)
        input_data = f'{server_time}~{md5_text(video_data_url)}~{md5_text(server_time)}'

        auth_secret = intlist_to_bytes(aes_encrypt(
            bytes_to_intlist(input_data[:64]), bytes_to_intlist(self._AUTH_KEY)))
        query = {
            'X-Anvato-Adst-Auth': base64.b64encode(auth_secret).decode('ascii'),
            'rtyp': 'fp',
        }
        anvrid = md5_text(time.time() * 1000 * random.random())[:30]
        api = {
            'anvrid': anvrid,
            'anvts': server_time,
        }
        if extracted_token is not None:
            api['anvstk2'] = extracted_token
        elif self._TOKEN_GENERATORS.get(access_key) is not None:
            api['anvstk2'] = self._TOKEN_GENERATORS[access_key](self, access_key, video_id)
        elif self._ANVACK_TABLE.get(access_key) is not None:
            api['anvstk'] = md5_text(f'{access_key}|{anvrid}|{server_time}|{self._ANVACK_TABLE[access_key]}')
        else:

Review comment (suggestion):
```suggestion
        return int_or_none(traverse_obj(self._download_json(
            f'{self._API_BASE_URL}/server_time', video_id, query={'anvack': access_key},
            note='Fetching server time', fatal=False), 'server_time')) or int(time.time())
```

Code after:
            headers={'X-Domain-Id': 100}, note='Fetching token info')
        token_type = reroute.get('token_type') or 'Bearer'
        auth_token = f'{token_type} {reroute["access_token"]}'
        response = self._download_json(
            'https://api.nfl.com/v3/shield/', mcp_id, data=json.dumps({
                'query': '''{
  viewer {
    mediaToken(anvack: "%s", id: %s) {
      token
    }
  }
}''' % (anvack, mcp_id),
            }).encode(), headers={
                'Authorization': auth_token,
                'Content-Type': 'application/json',
            }, note='Fetching NFL API token')
        return traverse_obj(response, ('data', 'viewer', 'mediaToken', 'token'))

    _TOKEN_GENERATORS = {
        'GXvEgwyJeWem8KCYXfeoHWknwP48Mboj': _generate_nfl_token,
    }

    def _server_time(self, access_key, video_id):
        return int_or_none(traverse_obj(self._download_json(
            f'{self._API_BASE_URL}/server_time', video_id, query={'anvack': access_key},
            note='Fetching server time', fatal=False), 'server_time')) or int(time.time())

    def _get_video_json(self, access_key, video_id, extracted_token):
        # See et() in anvplayer.min.js, which is an alias of getVideoJSON()
        video_data_url = f'{self._API_BASE_URL}/mcp/video/{video_id}?anvack={access_key}'
        server_time = self._server_time(access_key, video_id)
        input_data = f'{server_time}~{md5_text(video_data_url)}~{md5_text(server_time)}'

        auth_secret = intlist_to_bytes(aes_encrypt(
            bytes_to_intlist(input_data[:64]), bytes_to_intlist(self._AUTH_KEY)))
        query = {
            'X-Anvato-Adst-Auth': base64.b64encode(auth_secret).decode('ascii'),
            'rtyp': 'fp',
        }
        anvrid = md5_text(time.time() * 1000 * random.random())[:30]
        api = {
            'anvrid': anvrid,
            'anvts': server_time,
        }
        if extracted_token is not None:
            api['anvstk2'] = extracted_token
        elif self._TOKEN_GENERATORS.get(access_key) is not None:
            api['anvstk2'] = self._TOKEN_GENERATORS[access_key](self, access_key, video_id)
        elif self._ANVACK_TABLE.get(access_key) is not None:
            api['anvstk'] = md5_text(f'{access_key}|{anvrid}|{server_time}|{self._ANVACK_TABLE[access_key]}')
        else: