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

Code before:
                '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):
        server_time = int_or_none(self._download_json(
            f'{self._API_BASE_URL}/server_time', video_id, query={'anvack': access_key},
            note='Fetching server time').get('server_time'))

        if not server_time:
            self._SERVER_TIME = int(time.time())

        return server_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):
this is not caching correctly.
```py
    def _server_time(self, access_key, video_id):
        self._SERVER_TIME = self._SERVER_TIME or 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())

        return self._SERVER_TIME
```

Code after:
      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:
            api['anvstk2'] = 'default'

        return self._download_json(
            video_data_url, video_id, transform_source=strip_jsonp, query=query,
            data=json.dumps({'api': api}, separators=(',', ':')).encode('utf-8'))

    def _get_anvato_videos(self, access_key, video_id, token):
        video_data = self._get_video_json(access_key, video_id, token)