From bb98db29a109ae5783ee0bf41b8ef81da317df5b Mon Sep 17 00:00:00 2001 From: Mozi <29089388+pzhlkj6612@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:03:03 +0000 Subject: [PATCH] simplify _call_api --- yt_dlp/extractor/fifa.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/yt_dlp/extractor/fifa.py b/yt_dlp/extractor/fifa.py index 9540b46531..b79a17952c 100644 --- a/yt_dlp/extractor/fifa.py +++ b/yt_dlp/extractor/fifa.py @@ -52,17 +52,19 @@ def _real_initialize(self): }).encode()) self._HEADERS['x-chili-device-id'] = device_info['id'] - def _call_api(self, path, video_id, note=None, **kwargs): + def _call_api(self, path, video_id, note=None, headers=None, query=None, data=None): return self._download_json( - f'https://www.plus.fifa.com/flux-capacitor/api/v1//{path}', video_id, note, **kwargs) + f'https://www.plus.fifa.com/flux-capacitor/api/v1//{path}', video_id, note, headers={ + **self._HEADERS, + **(headers or {}), + }, query=query, data=data) def _real_extract(self, url): urlh = self._request_webpage(url, self._match_id(url)) video_id, display_id, locale = self._match_valid_url(urlh.url).group('id', 'display_id', 'locale') video_info = self._call_api( - 'videoasset', video_id, 'Downloading video asset', - headers=self._HEADERS, query={'catalog': video_id})[0] + 'videoasset', video_id, 'Downloading video asset', query={'catalog': video_id})[0] formats = [] subtitles = {} @@ -73,12 +75,12 @@ def _real_extract(self, url): ]: session_info = self._call_api( 'streaming/session', video_id, 'Getting streaming session', - headers={**self._HEADERS, 'x-chili-accept-stream': stream_type}, + headers={'x-chili-accept-stream': stream_type}, data=json.dumps({'videoAssetId': video_info['id'], 'autoPlay': False}).encode()) streams_info = self._call_api( 'streaming/urls', video_id, 'Getting streaming urls', - headers={**self._HEADERS, 'x-chili-streaming-session': session_info['id']}) + headers={'x-chili-streaming-session': session_info['id']}) for playlist_url in traverse_obj(streams_info, (..., 'url')): ext = determine_ext(playlist_url) @@ -115,8 +117,9 @@ def _preconnect_link(self): r']+\brel\s*=\s*"preconnect"[^>]+href\s*=\s*"([^"]+)"', self._download_webpage('https://fifa.com/', None), 'Preconnect Link') - def _call_api(self, path, video_id, note=None, **kwargs): - return self._download_json(f'{self._preconnect_link}/{path}', video_id, note, **kwargs) + def _call_api(self, path, video_id, note=None, query=None): + return self._download_json( + f'{self._preconnect_link}/{path}', video_id, note, query=query) class FifaIE(FifaBaseIE):