Compare commits

..

2 Commits

Author SHA1 Message Date
coletdjnz
d644aeb2c3
Only remove user agent if it matches.
In some cases we may want to provide a custom user agent
2024-01-01 14:38:04 +13:00
coletdjnz
cfdfeb0761
Improve docs 2024-01-01 11:40:09 +13:00
4 changed files with 11 additions and 9 deletions

View File

@ -289,7 +289,11 @@ While all the other dependencies are optional, `ffmpeg` and `ffprobe` are highly
* [**brotli**](https://github.com/google/brotli)\* or [**brotlicffi**](https://github.com/python-hyper/brotlicffi) - [Brotli](https://en.wikipedia.org/wiki/Brotli) content encoding support. Both licensed under MIT <sup>[1](https://github.com/google/brotli/blob/master/LICENSE) [2](https://github.com/python-hyper/brotlicffi/blob/master/LICENSE) </sup>
* [**websockets**](https://github.com/aaugustin/websockets)\* - For downloading over websocket. Licensed under [BSD-3-Clause](https://github.com/aaugustin/websockets/blob/main/LICENSE)
* [**requests**](https://github.com/psf/requests)\* - HTTP library. For HTTPS proxy and persistent connections support. Licensed under [Apache-2.0](https://github.com/psf/requests/blob/main/LICENSE)
* [**curl_cffi**](https://github.com/yifeikong/curl_cffi)\* - Python binding for [curl-impersonate](https://github.com/lwthiker/curl-impersonate). Provides impersonation support for chrome, edge and safari. Licensed under [MIT](https://github.com/yifeikong/curl_cffi/blob/main/LICENSE)
#### Impersonation
The following provide support for impersonating browser requests. This may be required for some sites that employ TLS fingerprinting and other checks.
* [**curl_cffi**](https://github.com/yifeikong/curl_cffi)\* (recommended) - Python binding for [curl-impersonate](https://github.com/lwthiker/curl-impersonate). Provides impersonation targets for Chrome, Edge and Safari. Licensed under [MIT](https://github.com/yifeikong/curl_cffi/blob/main/LICENSE)
### Metadata

View File

@ -157,6 +157,7 @@ from .utils import (
windows_enable_vt_mode,
write_json_file,
write_string,
YoutubeDLError,
)
from .utils._utils import _YDLLogger
from .utils.networking import (
@ -714,9 +715,10 @@ class YoutubeDL:
impersonate_target = self.params.get('impersonate')
if impersonate_target is not None:
if not self.impersonate_target_available(impersonate_target):
raise ValueError(
raise YoutubeDLError(
f'Impersonate target "{self.params.get("impersonate")}" is not available. '
f'Use --list-impersonate-targets to see available targets.')
f'Use --list-impersonate-targets to see available targets. '
f'You may be missing dependencies required to support this target - check the manual for what dependencies you may need to install.')
if 'list-formats' in self.params['compat_opts']:
self.params['listformats_table'] = False
@ -4133,8 +4135,9 @@ class YoutubeDL:
elif re.match(r'unsupported (?:extensions: impersonate|impersonate target)', ue.msg.lower()):
raise RequestError(
f'Impersonate target "{req.extensions["impersonate"]}" is not available.'
f' See --list-impersonate-targets for available targets.'
f' This request requires browser impersonation, however you may be missing dependencies'
f' required to support this target. See the documentation for more information.')
f' required to support this target. Check the manual for what dependencies you may need to install.')
raise
except SSLError as e:
if 'UNSAFE_LEGACY_RENEGOTIATION_DISABLED' in str(e):

View File

@ -997,10 +997,6 @@ def _real_main(argv=None):
ydl.to_stdout(
render_table(['Client', 'Version', 'OS', 'OS Version', 'Source'], rows)
)
if not available_targets:
ydl.to_stdout('You are missing dependencies for impersonation. See the README for more info.')
ydl.to_stdout(
'If the above table is missing targets, you may be missing dependencies for impersonation.')
return
if not actual_use:

View File

@ -131,7 +131,6 @@ class ImpersonateRequestHandler(RequestHandler, ABC):
headers = self._merge_headers(request.headers)
if self._get_request_target(request) is not None:
# remove all headers present in std_headers
headers.pop('User-Agent', None)
for header in std_headers:
if header in headers and std_headers[header] == headers[header]:
headers.pop(header, None)