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