A feature-rich command-line audio/video downloader
[utils] Register SOCKS protocols in urllib and support SOCKS4A
Yen Chi Hsuan51fb4995a524
diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.pyindex a96482e680..34eeb77c5d 100755--- a/youtube_dl/YoutubeDL.py+++ b/youtube_dl/YoutubeDL.py@@ -64,6 +64,7 @@ from .utils import (PostProcessingError,preferredencoding,prepend_extension,+ register_socks_protocols,render_table,replace_extension,SameFileError,@@ -361,6 +362,8 @@ class YoutubeDL(object):for ph in self.params.get('progress_hooks', []):self.add_progress_hook(ph)+ register_socks_protocols()+def warn_if_short_id(self, argv):# short YouTube ID starting with dash?idxs = [diff --git a/youtube_dl/utils.py b/youtube_dl/utils.pyindex b2e4a2dfb7..c9702fd93f 100644--- a/youtube_dl/utils.py+++ b/youtube_dl/utils.py@@ -61,6 +61,13 @@ from .socks import ()+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 otherwisecompiled_regex_type = type(re.compile(''))@@ -870,6 +877,8 @@ def make_socks_conn_class(base_class, socks_proxy):socks_type = ProxyType.SOCKS5elif url_components.scheme.lower() in ('socks', 'socks4'):socks_type = ProxyType.SOCKS4+ elif url_components.scheme.lower() == 'socks4a':+ socks_type = ProxyType.SOCKS4Aproxy_args = (socks_type,@@ -2738,7 +2747,7 @@ class PerRequestProxyHandler(compat_urllib_request.ProxyHandler):if proxy == '__noproxy__':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)# youtube-dl's http/https handlers do wrapping the socket with socksreturn None