mirror of
https://github.com/l1ving/youtube-dl
synced 2025-03-13 11:27:30 +08:00
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 traceback
|
||||
|
||||
# Try to import socks
|
||||
try:
|
||||
import socks
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
if os.name == 'nt':
|
||||
import ctypes
|
||||
|
||||
@ -1825,6 +1831,28 @@ class YoutubeDL(object):
|
||||
proxies['https'] = proxies['http']
|
||||
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
|
||||
https_handler = make_HTTPS_handler(self.params, debuglevel=debuglevel)
|
||||
ydlh = YoutubeDLHandler(self.params, debuglevel=debuglevel)
|
||||
|
@ -346,6 +346,7 @@ def _real_main(argv=None):
|
||||
'nocheckcertificate': opts.no_check_certificate,
|
||||
'prefer_insecure': opts.prefer_insecure,
|
||||
'proxy': opts.proxy,
|
||||
'socksproxy': opts.socksproxy,
|
||||
'socket_timeout': opts.socket_timeout,
|
||||
'bidi_workaround': opts.bidi_workaround,
|
||||
'debug_printtraffic': opts.debug_printtraffic,
|
||||
|
@ -181,6 +181,10 @@ def parseOpts(overrideArguments=None):
|
||||
'--proxy', dest='proxy',
|
||||
default=None, metavar='URL',
|
||||
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(
|
||||
'--socket-timeout',
|
||||
dest='socket_timeout', type=float, default=None, metavar='SECONDS',
|
||||
|
Loading…
x
Reference in New Issue
Block a user