mirror of
https://github.com/soimort/you-get.git
synced 2025-01-23 13:35:16 +03:00
Merge branch 'timeout_retry' of https://github.com/JayXon/you-get into JayXon-timeout_retry
This commit is contained in:
commit
f7350381b6
@ -98,6 +98,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import re
|
import re
|
||||||
|
import socket
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from urllib import request, parse, error
|
from urllib import request, parse, error
|
||||||
@ -308,7 +309,14 @@ def get_content(url, headers={}, decoded=True):
|
|||||||
if cookies:
|
if cookies:
|
||||||
cookies.add_cookie_header(req)
|
cookies.add_cookie_header(req)
|
||||||
req.headers.update(req.unredirected_hdrs)
|
req.headers.update(req.unredirected_hdrs)
|
||||||
|
|
||||||
|
for i in range(10):
|
||||||
|
try:
|
||||||
response = request.urlopen(req)
|
response = request.urlopen(req)
|
||||||
|
break
|
||||||
|
except socket.timeout:
|
||||||
|
logging.debug('request attempt %s timeout' % str(i + 1))
|
||||||
|
|
||||||
data = response.read()
|
data = response.read()
|
||||||
|
|
||||||
# Handle HTTP compression for gzip and deflate (zlib)
|
# Handle HTTP compression for gzip and deflate (zlib)
|
||||||
@ -1063,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
|
||||||
@ -1097,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()
|
||||||
@ -1170,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)
|
||||||
@ -1179,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