Add --socks-proxy parameter to use socks proxy
This allows the user to specify a socks proxy to tunnel the connection through.
This commit is contained in:
parent
420658e6cb
commit
18edc5c5cf
@ -23,6 +23,12 @@ import sys
|
|||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
# Try to import socks
|
||||||
|
try:
|
||||||
|
import socks
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
import ctypes
|
import ctypes
|
||||||
|
|
||||||
@ -1825,6 +1831,28 @@ class YoutubeDL(object):
|
|||||||
proxies['https'] = proxies['http']
|
proxies['https'] = proxies['http']
|
||||||
proxy_handler = PerRequestProxyHandler(proxies)
|
proxy_handler = PerRequestProxyHandler(proxies)
|
||||||
|
|
||||||
|
if 'socks' in sys.modules: # Check if socks was imported
|
||||||
|
opts_socks = self.params.get('socksproxy')
|
||||||
|
|
||||||
|
print("Socks {}".format(opts_socks))
|
||||||
|
if opts_socks is not None and opts_socks:
|
||||||
|
pair = opts_socks.split(':')
|
||||||
|
if len(pair) == 2:
|
||||||
|
socks.setdefaultproxy(
|
||||||
|
socks.PROXY_TYPE_SOCKS5,
|
||||||
|
pair[0],
|
||||||
|
int(pair[1]))
|
||||||
|
else:
|
||||||
|
socks.setdefaultproxy(
|
||||||
|
socks.PROXY_TYPE_SOCKS5,
|
||||||
|
'localhost',
|
||||||
|
int(pair[0]))
|
||||||
|
|
||||||
|
socks.wrapmodule(compat_urllib_request)
|
||||||
|
else: # Socks was not imported, but the use tried to use it. Tell them
|
||||||
|
if self.params.get('socksproxy'):
|
||||||
|
self.to_stdout("Can't use socks proxy, socks module not found")
|
||||||
|
|
||||||
debuglevel = 1 if self.params.get('debug_printtraffic') else 0
|
debuglevel = 1 if self.params.get('debug_printtraffic') else 0
|
||||||
https_handler = make_HTTPS_handler(self.params, debuglevel=debuglevel)
|
https_handler = make_HTTPS_handler(self.params, debuglevel=debuglevel)
|
||||||
ydlh = YoutubeDLHandler(self.params, debuglevel=debuglevel)
|
ydlh = YoutubeDLHandler(self.params, debuglevel=debuglevel)
|
||||||
|
@ -346,6 +346,7 @@ def _real_main(argv=None):
|
|||||||
'nocheckcertificate': opts.no_check_certificate,
|
'nocheckcertificate': opts.no_check_certificate,
|
||||||
'prefer_insecure': opts.prefer_insecure,
|
'prefer_insecure': opts.prefer_insecure,
|
||||||
'proxy': opts.proxy,
|
'proxy': opts.proxy,
|
||||||
|
'socksproxy': opts.socksproxy,
|
||||||
'socket_timeout': opts.socket_timeout,
|
'socket_timeout': opts.socket_timeout,
|
||||||
'bidi_workaround': opts.bidi_workaround,
|
'bidi_workaround': opts.bidi_workaround,
|
||||||
'debug_printtraffic': opts.debug_printtraffic,
|
'debug_printtraffic': opts.debug_printtraffic,
|
||||||
|
@ -181,6 +181,10 @@ def parseOpts(overrideArguments=None):
|
|||||||
'--proxy', dest='proxy',
|
'--proxy', dest='proxy',
|
||||||
default=None, metavar='URL',
|
default=None, metavar='URL',
|
||||||
help='Use the specified HTTP/HTTPS proxy. Pass in an empty string (--proxy "") for direct connection')
|
help='Use the specified HTTP/HTTPS proxy. Pass in an empty string (--proxy "") for direct connection')
|
||||||
|
network.add_option(
|
||||||
|
'--socks-proxy', dest='socksproxy', default=None, metavar='URL',
|
||||||
|
help=('Use the specified socks proxy. Pass in an empty string '
|
||||||
|
'(--socks-proxy "") for direct connection'))
|
||||||
network.add_option(
|
network.add_option(
|
||||||
'--socket-timeout',
|
'--socket-timeout',
|
||||||
dest='socket_timeout', type=float, default=None, metavar='SECONDS',
|
dest='socket_timeout', type=float, default=None, metavar='SECONDS',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user