clean up
This commit is contained in:
parent
d3df1c593a
commit
8475d928a2
28
stream.py
28
stream.py
@ -84,16 +84,15 @@ class ProxyElem():
|
||||
return data["upstream"]
|
||||
|
||||
class AsyncSessionData():
|
||||
def __init__(self, resp, current_proxies, current_proxy):
|
||||
def __init__(self, resp, current):
|
||||
self.resp = resp
|
||||
self.current_proxies = current_proxies
|
||||
self.current_proxy = current_proxy
|
||||
self.current = current
|
||||
class AsyncSession():
|
||||
def __init__(self, resp, current_proxies, current_proxy):
|
||||
self.sdata = AsyncSessionData(resp, current_proxies, current_proxy)
|
||||
def __init__(self, resp, current):
|
||||
self.sdata = AsyncSessionData(resp, current)
|
||||
async def task(self):
|
||||
resp = await self.sdata.resp
|
||||
return AsyncSessionData(resp, self.sdata.current_proxies, self.sdata.current_proxy)
|
||||
return AsyncSessionData(resp, self.sdata.current)
|
||||
|
||||
proxies = {}
|
||||
for key in providers:
|
||||
@ -140,22 +139,14 @@ class UpstreamHandler():
|
||||
self.stream_url = f'{handler.request.path}?provider={self.provider}'
|
||||
|
||||
src = providers[self.provider] + path
|
||||
proxy_list = None
|
||||
proxy_iter = None
|
||||
proxy_list_orig = proxies.get(self.provider)
|
||||
if isinstance(proxy_list_orig, list):
|
||||
proxy_list = proxy_list_orig.copy()
|
||||
proxy_iter = proxy_list_orig.copy()
|
||||
proxy_list = proxies.get(self.provider)
|
||||
if isinstance(proxy_list, list):
|
||||
futures = []
|
||||
sessions = []
|
||||
for i in proxy_iter:
|
||||
current_list = proxy_list.copy()
|
||||
current = proxy_list.pop()
|
||||
proxy_list = [current] + proxy_list
|
||||
for current in proxy_list:
|
||||
session = current.session()
|
||||
sessions.append(session)
|
||||
future = AsyncSession(session.head(src), current_list, current)
|
||||
future = AsyncSession(session.head(src), current)
|
||||
task = asyncio.create_task(future.task())
|
||||
futures.append(task)
|
||||
done = False
|
||||
@ -174,8 +165,7 @@ class UpstreamHandler():
|
||||
else:
|
||||
self.upstream = new_url
|
||||
self.upstream_safe = urllib.parse.quote(new_url)
|
||||
self.proxy = result.current_proxy
|
||||
proxies[self.provider] = result.current_proxies
|
||||
self.proxy = result.current
|
||||
break
|
||||
for future in futures:
|
||||
if not future.done():
|
||||
|
Loading…
Reference in New Issue
Block a user