This commit is contained in:
whew 2022-12-28 14:20:50 +02:00 committed by GitHub
commit b02b3b3e50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 5 deletions

View file

@ -101,7 +101,7 @@ Alternatively, refer to the [developer instructions](#developer-instructions) fo
--proxy URL Use the specified HTTP/HTTPS/SOCKS --proxy URL Use the specified HTTP/HTTPS/SOCKS
proxy. To enable SOCKS proxy, specify a proxy. To enable SOCKS proxy, specify a
proper scheme. For example proper scheme. For example
socks5://127.0.0.1:1080/. Pass in an socks5h://127.0.0.1:1080/. Pass in an
empty string (--proxy "") for direct empty string (--proxy "") for direct
connection connection
--socket-timeout SECONDS Time to wait before giving up, in --socket-timeout SECONDS Time to wait before giving up, in

View file

@ -113,6 +113,8 @@ class TestSocks(unittest.TestCase):
def test_socks5(self): def test_socks5(self):
self.assertTrue(isinstance(self._get_ip('socks5'), compat_str)) self.assertTrue(isinstance(self._get_ip('socks5'), compat_str))
def test_socks5h(self):
self.assertTrue(isinstance(self._get_ip('socks5h'), compat_str))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View file

@ -205,7 +205,7 @@ def parseOpts(overrideArguments=None):
default=None, metavar='URL', default=None, metavar='URL',
help='Use the specified HTTP/HTTPS/SOCKS proxy. To enable ' help='Use the specified HTTP/HTTPS/SOCKS proxy. To enable '
'SOCKS proxy, specify a proper scheme. For example ' 'SOCKS proxy, specify a proper scheme. For example '
'socks5://127.0.0.1:1080/. Pass in an empty string (--proxy "") ' 'socks5h://127.0.0.1:1080/. Pass in an empty string (--proxy "") '
'for direct connection') 'for direct connection')
network.add_option( network.add_option(
'--socket-timeout', '--socket-timeout',

View file

@ -79,7 +79,7 @@ def register_socks_protocols():
# "Register" SOCKS protocols # "Register" SOCKS protocols
# In Python < 2.6.5, urlsplit() suffers from bug https://bugs.python.org/issue7904 # In Python < 2.6.5, urlsplit() suffers from bug https://bugs.python.org/issue7904
# URLs with protocols not in urlparse.uses_netloc are not handled correctly # URLs with protocols not in urlparse.uses_netloc are not handled correctly
for scheme in ('socks', 'socks4', 'socks4a', 'socks5'): for scheme in ('socks', 'socks4', 'socks4a', 'socks5', 'socks5h'):
if scheme not in compat_urlparse.uses_netloc: if scheme not in compat_urlparse.uses_netloc:
compat_urlparse.uses_netloc.append(scheme) compat_urlparse.uses_netloc.append(scheme)
@ -2726,7 +2726,7 @@ def make_socks_conn_class(base_class, socks_proxy):
compat_http_client.HTTPConnection, compat_http_client.HTTPSConnection)) compat_http_client.HTTPConnection, compat_http_client.HTTPSConnection))
url_components = compat_urlparse.urlparse(socks_proxy) url_components = compat_urlparse.urlparse(socks_proxy)
if url_components.scheme.lower() == 'socks5': if url_components.scheme.lower() in ('socks5', 'socks5h'):
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
@ -5586,7 +5586,7 @@ class PerRequestProxyHandler(compat_urllib_request.ProxyHandler):
if proxy == '__noproxy__': if proxy == '__noproxy__':
return None # No Proxy return None # No Proxy
if compat_urlparse.urlparse(proxy).scheme.lower() in ('socks', 'socks4', 'socks4a', 'socks5'): if compat_urlparse.urlparse(proxy).scheme.lower() in ('socks', 'socks4', 'socks4a', 'socks5', 'socks5h'):
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