diff --git a/stream.py b/stream.py index eabd4f0..7fded1e 100755 --- a/stream.py +++ b/stream.py @@ -160,25 +160,27 @@ class UpstreamHandler(): futures.append(task) done = False for future in asyncio.as_completed(futures): - if done: - future.cancel() + try: + result = await future + resp = result.resp + except Exception as e: + logger.info(e) else: - try: - result = await future - resp = result.resp - except Exception as e: - logger.info(e) + done = True + new_url = str(resp.url) + if new_url.lower().startswith("https://consent.youtube.com"): + self.upstream = src + self.upstream_safe = urllib.parse.quote(src) else: - done = True - new_url = str(resp.url) - if new_url.lower().startswith("https://consent.youtube.com"): - self.upstream = src - self.upstream_safe = urllib.parse.quote(src) - 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.upstream = new_url + self.upstream_safe = urllib.parse.quote(new_url) + self.proxy = result.current_proxy + proxies[self.provider] = result.current_proxies + break + for future in futures: + if not future.done(): + future.cancel() + async def meta(self): data = [] try: