Merge branch 'supportignoressl' of https://github.com/gaoxingliang/you-get into gaoxingliang-supportignoressl

This commit is contained in:
Mort Yao 2019-03-25 15:32:27 +01:00
commit 2e461820f8
No known key found for this signature in database
GPG Key ID: 07DA00CB78203251

View File

@ -10,6 +10,7 @@ import socket
import locale
import logging
import argparse
import ssl
from http import cookiejar
from importlib import import_module
from urllib import request, parse, error
@ -135,6 +136,7 @@ extractor_proxy = None
cookies = None
output_filename = None
auto_rename = False
insecure = False
fake_headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', # noqa
@ -391,7 +393,14 @@ def urlopen_with_retry(*args, **kwargs):
retry_time = 3
for i in range(retry_time):
try:
return request.urlopen(*args, **kwargs)
if insecure:
# ignore ssl errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
return request.urlopen(*args, context=ctx, **kwargs)
else:
return request.urlopen(*args, **kwargs)
except socket.timeout as e:
logging.debug('request attempt %s timeout' % str(i + 1))
if i + 1 == retry_time:
@ -1489,6 +1498,11 @@ def script_main(download, download_playlist, **kwargs):
help='Auto rename same name different files'
)
download_grp.add_argument(
'-k', '--insecure', action='store_true', default=False,
help='ignore ssl errors'
)
proxy_grp = parser.add_argument_group('Proxy options')
proxy_grp = proxy_grp.add_mutually_exclusive_group()
proxy_grp.add_argument(
@ -1533,7 +1547,7 @@ def script_main(download, download_playlist, **kwargs):
global extractor_proxy
global output_filename
global auto_rename
global insecure
output_filename = args.output_filename
extractor_proxy = args.extractor_proxy
@ -1561,6 +1575,11 @@ def script_main(download, download_playlist, **kwargs):
player = args.player
caption = False
if args.insecure:
# ignore ssl
insecure = True
if args.no_proxy:
set_http_proxy('')
else: