Skip to content
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

Accept socks5h:// proxy protocol name #28093

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Alternatively, refer to the [developer instructions](#developer-instructions) fo
--proxy URL Use the specified HTTP/HTTPS/SOCKS
proxy. To enable SOCKS proxy, specify a
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
connection
--socket-timeout SECONDS Time to wait before giving up, in
Expand Down
2 changes: 2 additions & 0 deletions test/test_socks.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def test_socks4a(self):
def test_socks5(self):
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__':
unittest.main()
2 changes: 1 addition & 1 deletion youtube_dl/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def _comma_separated_values_options_callback(option, opt_str, value, parser):
default=None, metavar='URL',
help='Use the specified HTTP/HTTPS/SOCKS proxy. To enable '
'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')
network.add_option(
'--socket-timeout',
Expand Down
6 changes: 3 additions & 3 deletions youtube_dl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def register_socks_protocols():
# "Register" SOCKS protocols
# 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
for scheme in ('socks', 'socks4', 'socks4a', 'socks5'):
for scheme in ('socks', 'socks4', 'socks4a', 'socks5', 'socks5h'):
if scheme not in compat_urlparse.uses_netloc:
compat_urlparse.uses_netloc.append(scheme)

Expand Down Expand Up @@ -2673,7 +2673,7 @@ def make_socks_conn_class(base_class, socks_proxy):
compat_http_client.HTTPConnection, compat_http_client.HTTPSConnection))

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
elif url_components.scheme.lower() in ('socks', 'socks4'):
socks_type = ProxyType.SOCKS4
Expand Down Expand Up @@ -5352,7 +5352,7 @@ def proxy_open(self, req, proxy, type):

if proxy == '__noproxy__':
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)
# youtube-dl's http/https handlers do wrapping the socket with socks
return None
Expand Down