Skip to content

Commit

Permalink
[ie/crunchyroll] Support browser impersonation (#9857)
Browse files Browse the repository at this point in the history
Closes #7442
Authored by: bashonly
  • Loading branch information
bashonly committed May 5, 2024
1 parent c8bf48f commit 5904853
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions yt_dlp/extractor/crunchyroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,19 @@ def _set_auth_info(self, response):
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)

Expand Down

0 comments on commit 5904853

Please sign in to comment.