proxy selection logic
This commit is contained in:
parent
02f8786414
commit
8a113fbb41
11
stream.py
11
stream.py
@ -166,11 +166,19 @@ class MainHandler(tornado.web.RequestHandler):
|
|||||||
path = path.strip("/")
|
path = path.strip("/")
|
||||||
src = providers[provider] + self.request.path
|
src = providers[provider] + self.request.path
|
||||||
proxy_list = None
|
proxy_list = None
|
||||||
|
new_proxy_list = None
|
||||||
proxy_list_orig = proxies.get(provider)
|
proxy_list_orig = proxies.get(provider)
|
||||||
if isinstance(proxy_list_orig, list):
|
if isinstance(proxy_list_orig, list):
|
||||||
proxy_list = proxy_list_orig.copy()
|
proxy_list = proxy_list_orig.copy()
|
||||||
|
new_proxy_list = proxy_list_orig.copy()
|
||||||
|
if len(new_proxy_list) > 1:
|
||||||
|
first_proxy = new_proxy_list.pop()
|
||||||
|
new_proxy_list = [first_proxy] + new_proxy_list
|
||||||
if isinstance(proxy_list, list):
|
if isinstance(proxy_list, list):
|
||||||
for proxy_temp in proxy_list:
|
for proxy_temp in proxy_list:
|
||||||
|
if len(proxy_list) > 1:
|
||||||
|
first_proxy = new_proxy_list.pop(0)
|
||||||
|
new_proxy_list = new_proxy_list + [first_proxy]
|
||||||
try:
|
try:
|
||||||
resp = requests.head(src, allow_redirects=True, proxies=proxy_temp.req, timeout=(0.3, 2.0))
|
resp = requests.head(src, allow_redirects=True, proxies=proxy_temp.req, timeout=(0.3, 2.0))
|
||||||
if resp is not None:
|
if resp is not None:
|
||||||
@ -178,8 +186,7 @@ class MainHandler(tornado.web.RequestHandler):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
else:
|
else:
|
||||||
proxy_list.remove(proxy_temp)
|
proxies[provider] = new_proxy_list
|
||||||
proxies[provider] = [proxy_temp] + proxy_list
|
|
||||||
proxy = proxy_temp
|
proxy = proxy_temp
|
||||||
break
|
break
|
||||||
if proxy is not None:
|
if proxy is not None:
|
||||||
|
Loading…
Reference in New Issue
Block a user