New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[networking] Add response extensions for impersonate info #9756
Conversation
Authored by: bashonly
Authored by: bashonly
Pls explain motivation for 3b48105. I liked the first impl much better |
hypothetically, the value of yt-dlp/yt_dlp/networking/impersonate.py Lines 61 to 80 in 52f5be1
so if a response is an instance of from ..networking.impersonate import ImpersonateResponse
try:
...
except ExtractorError as e:
if isinstance(e.cause, HTTPError) and e.cause.status == 403:
if isinstance(e.cause.response, ImpersonateResponse) and e.cause.response.impersonate is not None:
target = str(e.cause.response.impersonate)
# handling for impersonation
# handling for no impersonation vs. with new impl: try:
...
except ExtractorError as e:
if isinstance(e.cause, HTTPError) and e.cause.status == 403:
if target := e.cause.response.extras.get('impersonate'):
# handling for impersonation
# handling for no impersonation |
Why not Alternatively, we could put an |
Authored by: bashonly
That should suffice, yeah. I've reverted to the orig impl (but kept the corrected type annotations)
IMO the base |
ImpersonateResponse
Authored by: bashonly
Authored by: bashonly
Authored by: bashonly
this can be useful during extractor error handling, e.g. in the crunchyroll extractor, where we want to expect the 403 error and a offer a cloudflare bypass hint if impersonation was not used, or else raise w/ a bug report message if impersonation was used.
Template
Before submitting a pull request make sure you have:
In order to be accepted and merged into yt-dlp each piece of code must be in public domain or released under Unlicense. Check all of the following options that apply:
What is the purpose of your pull request?