From 8475d928a20ef9ce14c07f71e5fb7cd3cad43de8 Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Fri, 14 May 2021 23:18:51 +0200 Subject: [PATCH] clean up --- stream.py | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/stream.py b/stream.py index 337802c..d5395d6 100755 --- a/stream.py +++ b/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():