mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-27 18:41:29 +00:00
[utils] Register SOCKS protocols in urllib and support SOCKS4A
This commit is contained in:
parent
9e9cd7248d
commit
51fb4995a5
|
@ -64,6 +64,7 @@
|
||||||
PostProcessingError,
|
PostProcessingError,
|
||||||
preferredencoding,
|
preferredencoding,
|
||||||
prepend_extension,
|
prepend_extension,
|
||||||
|
register_socks_protocols,
|
||||||
render_table,
|
render_table,
|
||||||
replace_extension,
|
replace_extension,
|
||||||
SameFileError,
|
SameFileError,
|
||||||
|
@ -361,6 +362,8 @@ def __init__(self, params=None, auto_init=True):
|
||||||
for ph in self.params.get('progress_hooks', []):
|
for ph in self.params.get('progress_hooks', []):
|
||||||
self.add_progress_hook(ph)
|
self.add_progress_hook(ph)
|
||||||
|
|
||||||
|
register_socks_protocols()
|
||||||
|
|
||||||
def warn_if_short_id(self, argv):
|
def warn_if_short_id(self, argv):
|
||||||
# short YouTube ID starting with dash?
|
# short YouTube ID starting with dash?
|
||||||
idxs = [
|
idxs = [
|
||||||
|
|
|
@ -61,6 +61,13 @@
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def register_socks_protocols():
|
||||||
|
# "Register" SOCKS protocols
|
||||||
|
for scheme in ('socks', 'socks4', 'socks4a', 'socks5'):
|
||||||
|
if scheme not in compat_urlparse.uses_netloc:
|
||||||
|
compat_urlparse.uses_netloc.append(scheme)
|
||||||
|
|
||||||
|
|
||||||
# This is not clearly defined otherwise
|
# This is not clearly defined otherwise
|
||||||
compiled_regex_type = type(re.compile(''))
|
compiled_regex_type = type(re.compile(''))
|
||||||
|
|
||||||
|
@ -870,6 +877,8 @@ def make_socks_conn_class(base_class, socks_proxy):
|
||||||
socks_type = ProxyType.SOCKS5
|
socks_type = ProxyType.SOCKS5
|
||||||
elif url_components.scheme.lower() in ('socks', 'socks4'):
|
elif url_components.scheme.lower() in ('socks', 'socks4'):
|
||||||
socks_type = ProxyType.SOCKS4
|
socks_type = ProxyType.SOCKS4
|
||||||
|
elif url_components.scheme.lower() == 'socks4a':
|
||||||
|
socks_type = ProxyType.SOCKS4A
|
||||||
|
|
||||||
proxy_args = (
|
proxy_args = (
|
||||||
socks_type,
|
socks_type,
|
||||||
|
@ -2738,7 +2747,7 @@ def proxy_open(self, req, proxy, type):
|
||||||
|
|
||||||
if proxy == '__noproxy__':
|
if proxy == '__noproxy__':
|
||||||
return None # No Proxy
|
return None # No Proxy
|
||||||
if compat_urlparse.urlparse(proxy).scheme.lower() in ('socks', 'socks4', 'socks5'):
|
if compat_urlparse.urlparse(proxy).scheme.lower() in ('socks', 'socks4', 'socks4a', 'socks5'):
|
||||||
req.add_header('Ytdl-socks-proxy', proxy)
|
req.add_header('Ytdl-socks-proxy', proxy)
|
||||||
# youtube-dl's http/https handlers do wrapping the socket with socks
|
# youtube-dl's http/https handlers do wrapping the socket with socks
|
||||||
return None
|
return None
|
||||||
|
|
Loading…
Reference in a new issue