mirror of https://github.com/yt-dlp/yt-dlp.git
[ie/crunchyroll] Support browser impersonation (#9857)
Closes #7442 Authored by: bashonly
This commit is contained in:
parent
c8bf48f3a8
commit
5904853ae5
|
@ -53,15 +53,19 @@ class CrunchyrollBaseIE(InfoExtractor):
|
||||||
CrunchyrollBaseIE._AUTH_EXPIRY = time_seconds(seconds=traverse_obj(response, ('expires_in', {float_or_none}), default=300) - 10)
|
CrunchyrollBaseIE._AUTH_EXPIRY = time_seconds(seconds=traverse_obj(response, ('expires_in', {float_or_none}), default=300) - 10)
|
||||||
|
|
||||||
def _request_token(self, headers, data, note='Requesting token', errnote='Failed to request token'):
|
def _request_token(self, headers, data, note='Requesting token', errnote='Failed to request token'):
|
||||||
try: # TODO: Add impersonation support here
|
try:
|
||||||
return self._download_json(
|
return self._download_json(
|
||||||
f'{self._BASE_URL}/auth/v1/token', None, note=note, errnote=errnote,
|
f'{self._BASE_URL}/auth/v1/token', None, note=note, errnote=errnote,
|
||||||
headers=headers, data=urlencode_postdata(data))
|
headers=headers, data=urlencode_postdata(data), impersonate=True)
|
||||||
except ExtractorError as error:
|
except ExtractorError as error:
|
||||||
if not isinstance(error.cause, HTTPError) or error.cause.status != 403:
|
if not isinstance(error.cause, HTTPError) or error.cause.status != 403:
|
||||||
raise
|
raise
|
||||||
|
if target := error.cause.response.extensions.get('impersonate'):
|
||||||
|
raise ExtractorError(f'Got HTTP Error 403 when using impersonate target "{target}"')
|
||||||
raise ExtractorError(
|
raise ExtractorError(
|
||||||
'Request blocked by Cloudflare; navigate to Crunchyroll in your browser, '
|
'Request blocked by Cloudflare. '
|
||||||
|
'Install the required impersonation dependency if possible, '
|
||||||
|
'or else navigate to Crunchyroll in your browser, '
|
||||||
'then pass the fresh cookies (with --cookies-from-browser or --cookies) '
|
'then pass the fresh cookies (with --cookies-from-browser or --cookies) '
|
||||||
'and your browser\'s User-Agent (with --user-agent)', expected=True)
|
'and your browser\'s User-Agent (with --user-agent)', expected=True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue