diff --git a/src/you_get/common.py b/src/you_get/common.py index 100f3869..119640d5 100755 --- a/src/you_get/common.py +++ b/src/you_get/common.py @@ -1071,12 +1071,13 @@ def script_main(script_name, download, download_playlist, **kwargs): -x | --http-proxy Use an HTTP proxy for downloading. -y | --extractor-proxy Use an HTTP proxy for extracting only. --no-proxy Never use a proxy. + -s | --socks-proxy Use an SOCKS5 proxy for downloading. -t | --timeout Set socket timeout. -d | --debug Show traceback and other debug info. ''' - short_opts = 'Vhfiuc:ndF:O:o:p:x:y:t:' - opts = ['version', 'help', 'force', 'info', 'url', 'cookies', 'no-caption', 'no-merge', 'no-proxy', 'debug', 'json', 'format=', 'stream=', 'itag=', 'output-filename=', 'output-dir=', 'player=', 'http-proxy=', 'extractor-proxy=', 'lang=', 'timeout='] + short_opts = 'Vhfiuc:ndF:O:o:p:x:y:s:t:' + opts = ['version', 'help', 'force', 'info', 'url', 'cookies', 'no-caption', 'no-merge', 'no-proxy', 'debug', 'json', 'format=', 'stream=', 'itag=', 'output-filename=', 'output-dir=', 'player=', 'http-proxy=', 'socks-proxy=', 'extractor-proxy=', 'lang=', 'timeout='] if download_playlist: short_opts = 'l' + short_opts opts = ['playlist'] + opts @@ -1104,6 +1105,7 @@ def script_main(script_name, download, download_playlist, **kwargs): lang = None output_dir = '.' proxy = None + socks_proxy = None extractor_proxy = None traceback = False timeout = 600 @@ -1176,6 +1178,8 @@ def script_main(script_name, download, download_playlist, **kwargs): caption = False elif o in ('-x', '--http-proxy'): proxy = a + elif o in ('-s', '--socks-proxy'): + socks_proxy = a elif o in ('-y', '--extractor-proxy'): extractor_proxy = a elif o in ('--lang',): @@ -1189,7 +1193,21 @@ def script_main(script_name, download, download_playlist, **kwargs): print(help) sys.exit() - set_http_proxy(proxy) + if (socks_proxy): + try: + import socket + import socks + socks_proxy_addrs = socks_proxy.split(':') + socks.set_default_proxy(socks.SOCKS5, + socks_proxy_addrs[0], + int(socks_proxy_addrs[1])) + socket.socket = socks.socksocket + except ImportError: + log.w('Error importing PySocks library, socks proxy ignored.' + 'In order to use use socks proxy, please install PySocks.') + else: + import socket + set_http_proxy(proxy) socket.setdefaulttimeout(timeout)