future stuff

This commit is contained in:
Roy Olav Purser 2021-05-14 19:13:18 +02:00
parent bca13c0d4a
commit b0b0055d75
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -6,6 +6,7 @@ import re
import os import os
import base64 import base64
import logging import logging
import asyncio
import streamlink import streamlink
import tornado.web import tornado.web
import tornado.routing import tornado.routing
@ -56,8 +57,6 @@ class ProxyElem():
logger.info(e) logger.info(e)
return ctype return ctype
async def proxy_url(self, current, path): async def proxy_url(self, current, path):
if proxy_server is None:
return data["upstream"]
jdata = None jdata = None
data = {} data = {}
data_list = [data] data_list = [data]
@ -66,11 +65,12 @@ class ProxyElem():
else: else:
data["upstream"] = urllib.parse.urljoin(current, path) data["upstream"] = urllib.parse.urljoin(current, path)
data["proxied"] = True data["proxied"] = True
ret = None
if self.proxy is None: if self.proxy is None:
data["proxied"] = False data["proxied"] = False
else: else:
data["proxy"] = self.proxy data["proxy"] = self.proxy
if proxy_server is None:
return data["upstream"]
try: try:
async with self.local() as session: async with self.local() as session:
resp = await session.post(proxy_server, json=data_list) resp = await session.post(proxy_server, json=data_list)
@ -148,22 +148,28 @@ class UpstreamHandler():
current = proxy_list.pop() current = proxy_list.pop()
proxy_list = [current] + proxy_list proxy_list = [current] + proxy_list
session = current.session() session = current.session()
delays.append(AsyncSession(session, session.head(src), current_list, current)) task = asyncio.create_task(session.head(src))
delays.append(AsyncSession(session, task, current_list, current))
done = False
for delay in delays: for delay in delays:
try: if done:
resp = await delay.future delay.future.cancel()
except Exception as e:
logger.info(e)
else: else:
new_url = str(resp.url) try:
if new_url.lower().startswith("https://consent.youtube.com"): resp = await delay.future
self.upstream = src except Exception as e:
self.upstream_safe = urllib.parse.quote(src) logger.info(e)
else: else:
self.upstream = new_url done = True
self.upstream_safe = urllib.parse.quote(new_url) new_url = str(resp.url)
self.proxy = delay.current_proxy if new_url.lower().startswith("https://consent.youtube.com"):
proxies[self.provider] = delay.current_proxies 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 = delay.current_proxy
proxies[self.provider] = delay.current_proxies
for delay in delays: for delay in delays:
try: try:
await delay.session.close() await delay.session.close()