mirror of
https://github.com/soimort/you-get.git
synced 2025-02-09 03:37:52 +03:00
Add -t and --timeout option
To set socket timeout, default is 600 seconds.
This commit is contained in:
parent
854386f22f
commit
48640e279f
@ -312,7 +312,7 @@ def get_content(url, headers={}, decoded=True):
|
|||||||
|
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
try:
|
try:
|
||||||
response = request.urlopen(req, timeout=10)
|
response = request.urlopen(req)
|
||||||
break
|
break
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
logging.debug('request attempt %s timeout' % str(i + 1))
|
logging.debug('request attempt %s timeout' % str(i + 1))
|
||||||
@ -1071,11 +1071,12 @@ def script_main(script_name, download, download_playlist, **kwargs):
|
|||||||
-x | --http-proxy <HOST:PORT> Use an HTTP proxy for downloading.
|
-x | --http-proxy <HOST:PORT> Use an HTTP proxy for downloading.
|
||||||
-y | --extractor-proxy <HOST:PORT> Use an HTTP proxy for extracting only.
|
-y | --extractor-proxy <HOST:PORT> Use an HTTP proxy for extracting only.
|
||||||
--no-proxy Never use a proxy.
|
--no-proxy Never use a proxy.
|
||||||
|
-t | --timeout <SECONDS> Set socket timeout.
|
||||||
-d | --debug Show traceback and other debug info.
|
-d | --debug Show traceback and other debug info.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
short_opts = 'Vhfiuc:ndF:O:o:p:x:y:'
|
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=']
|
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=']
|
||||||
if download_playlist:
|
if download_playlist:
|
||||||
short_opts = 'l' + short_opts
|
short_opts = 'l' + short_opts
|
||||||
opts = ['playlist'] + opts
|
opts = ['playlist'] + opts
|
||||||
@ -1105,6 +1106,7 @@ def script_main(script_name, download, download_playlist, **kwargs):
|
|||||||
proxy = None
|
proxy = None
|
||||||
extractor_proxy = None
|
extractor_proxy = None
|
||||||
traceback = False
|
traceback = False
|
||||||
|
timeout = 600
|
||||||
for o, a in opts:
|
for o, a in opts:
|
||||||
if o in ('-V', '--version'):
|
if o in ('-V', '--version'):
|
||||||
version()
|
version()
|
||||||
@ -1178,6 +1180,8 @@ def script_main(script_name, download, download_playlist, **kwargs):
|
|||||||
extractor_proxy = a
|
extractor_proxy = a
|
||||||
elif o in ('--lang',):
|
elif o in ('--lang',):
|
||||||
lang = a
|
lang = a
|
||||||
|
elif o in ('-t', '--timeout'):
|
||||||
|
timeout = int(a)
|
||||||
else:
|
else:
|
||||||
log.e("try 'you-get --help' for more options")
|
log.e("try 'you-get --help' for more options")
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
@ -1187,6 +1191,8 @@ def script_main(script_name, download, download_playlist, **kwargs):
|
|||||||
|
|
||||||
set_http_proxy(proxy)
|
set_http_proxy(proxy)
|
||||||
|
|
||||||
|
socket.setdefaulttimeout(timeout)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if stream_id:
|
if stream_id:
|
||||||
if not extractor_proxy:
|
if not extractor_proxy:
|
||||||
|
Loading…
Reference in New Issue
Block a user