mirror of
https://github.com/soimort/you-get.git
synced 2025-01-23 05:25:02 +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 platform
|
||||
import re
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
from urllib import request, parse, error
|
||||
@ -308,7 +309,14 @@ def get_content(url, headers={}, decoded=True):
|
||||
if cookies:
|
||||
cookies.add_cookie_header(req)
|
||||
req.headers.update(req.unredirected_hdrs)
|
||||
|
||||
for i in range(10):
|
||||
try:
|
||||
response = request.urlopen(req)
|
||||
break
|
||||
except socket.timeout:
|
||||
logging.debug('request attempt %s timeout' % str(i + 1))
|
||||
|
||||
data = response.read()
|
||||
|
||||
# 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.
|
||||
-y | --extractor-proxy <HOST:PORT> Use an HTTP proxy for extracting only.
|
||||
--no-proxy Never use a proxy.
|
||||
-t | --timeout <SECONDS> Set socket timeout.
|
||||
-d | --debug Show traceback and other debug info.
|
||||
'''
|
||||
|
||||
short_opts = 'Vhfiuc:ndF:O:o:p:x:y:'
|
||||
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=']
|
||||
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=']
|
||||
if download_playlist:
|
||||
short_opts = 'l' + short_opts
|
||||
opts = ['playlist'] + opts
|
||||
@ -1097,6 +1106,7 @@ def script_main(script_name, download, download_playlist, **kwargs):
|
||||
proxy = None
|
||||
extractor_proxy = None
|
||||
traceback = False
|
||||
timeout = 600
|
||||
for o, a in opts:
|
||||
if o in ('-V', '--version'):
|
||||
version()
|
||||
@ -1170,6 +1180,8 @@ def script_main(script_name, download, download_playlist, **kwargs):
|
||||
extractor_proxy = a
|
||||
elif o in ('--lang',):
|
||||
lang = a
|
||||
elif o in ('-t', '--timeout'):
|
||||
timeout = int(a)
|
||||
else:
|
||||
log.e("try 'you-get --help' for more options")
|
||||
sys.exit(2)
|
||||
@ -1179,6 +1191,8 @@ def script_main(script_name, download, download_playlist, **kwargs):
|
||||
|
||||
set_http_proxy(proxy)
|
||||
|
||||
socket.setdefaulttimeout(timeout)
|
||||
|
||||
try:
|
||||
if stream_id:
|
||||
if not extractor_proxy:
|
||||
|
Loading…
Reference in New Issue
Block a user