aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbashonly <88596187+bashonly@users.noreply.github.com>2024-05-05 18:15:32 -0500
committerGitHub <noreply@github.com>2024-05-05 23:15:32 +0000
commit5904853ae5788509fdc4892cb7ecdfa9ae7f78e6 (patch)
tree7d7c8637eef3dad6a5d2fb4d74d73cf6cbd9d035
parentc8bf48f3a8fa29587e7c73ef5a7710385a5ea725 (diff)
[ie/crunchyroll] Support browser impersonation (#9857)
Closes #7442 Authored by: bashonly
-rw-r--r--yt_dlp/extractor/crunchyroll.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/yt_dlp/extractor/crunchyroll.py b/yt_dlp/extractor/crunchyroll.py
index a157cddac..90967c160 100644
--- a/yt_dlp/extractor/crunchyroll.py
+++ b/yt_dlp/extractor/crunchyroll.py
@@ -53,15 +53,19 @@ class CrunchyrollBaseIE(InfoExtractor):
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'):
- try: # TODO: Add impersonation support here
+ try:
return self._download_json(
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:
if not isinstance(error.cause, HTTPError) or error.cause.status != 403:
raise
+ if target := error.cause.response.extensions.get('impersonate'):
+ raise ExtractorError(f'Got HTTP Error 403 when using impersonate target "{target}"')
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) '
'and your browser\'s User-Agent (with --user-agent)', expected=True)