mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-06-27 17:08:32 +00:00
_real_initialize()
-> cached _api_headers
field
implement review suggestions
This commit is contained in:
parent
876b5f7672
commit
4f208f7151
@ -1,14 +1,13 @@
|
|||||||
|
|
||||||
from urllib import parse
|
import functools
|
||||||
|
import urllib.parse
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..networking import HEADRequest
|
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
UserNotLive,
|
UserNotLive,
|
||||||
determine_ext,
|
determine_ext,
|
||||||
float_or_none,
|
float_or_none,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
merge_dicts,
|
|
||||||
parse_iso8601,
|
parse_iso8601,
|
||||||
str_or_none,
|
str_or_none,
|
||||||
traverse_obj,
|
traverse_obj,
|
||||||
@ -18,20 +17,18 @@
|
|||||||
|
|
||||||
|
|
||||||
class KickBaseIE(InfoExtractor):
|
class KickBaseIE(InfoExtractor):
|
||||||
def _real_initialize(self):
|
@functools.cached_property
|
||||||
self._request_webpage(
|
def _api_headers(self):
|
||||||
HEADRequest('https://kick.com/'), None, 'Setting up session', fatal=False, impersonate=True)
|
token = traverse_obj(
|
||||||
session_token = self._get_cookies('https://kick.com/').get('session_token')
|
self._get_cookies('https://kick.com/'),
|
||||||
if not session_token:
|
('session_token', 'value', {urllib.parse.unquote}),
|
||||||
self.write_debug('kick.com did not set session_token cookie')
|
)
|
||||||
KickBaseIE._API_HEADERS = {
|
return {'Authorization': f'Bearer {token}'} if token else {}
|
||||||
'Authorization': f'Bearer {parse.unquote(session_token.value)}',
|
|
||||||
} if session_token else {}
|
|
||||||
|
|
||||||
def _call_api(self, path, display_id, note='Downloading API JSON', headers={}, **kwargs):
|
def _call_api(self, path, display_id, note='Downloading API JSON', headers={}, **kwargs):
|
||||||
return self._download_json(
|
return self._download_json(
|
||||||
f'https://kick.com/api/{path}', display_id, note=note,
|
f'https://kick.com/api/{path}', display_id, note=note,
|
||||||
headers=merge_dicts(headers, self._API_HEADERS), impersonate=True, **kwargs)
|
headers={**self._api_headers, **headers}, impersonate=True, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class KickIE(KickBaseIE):
|
class KickIE(KickBaseIE):
|
||||||
|
Loading…
Reference in New Issue
Block a user