add direct mode
All checks were successful
continuous-integration/drone Build is passing

This commit is contained in:
Roy Olav Purser 2021-12-27 18:13:54 +01:00
parent 66a80f5526
commit 6d88564ebf
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -138,6 +138,7 @@ class UpstreamHandler():
self.raw = False self.raw = False
self.valid = False self.valid = False
self.proxy = ProxyElem(None) self.proxy = ProxyElem(None)
self.direct = False
self.upstream = None self.upstream = None
async def test_socks(self, proxy): async def test_socks(self, proxy):
if not hasattr(proxy, "proxy") or not isinstance(proxy.proxy, str): if not hasattr(proxy, "proxy") or not isinstance(proxy.proxy, str):
@ -158,9 +159,16 @@ class UpstreamHandler():
async def setup(self, handler): async def setup(self, handler):
self.provider = handler.get_query_argument("provider", None) self.provider = handler.get_query_argument("provider", None)
raw_str = handler.get_query_argument("raw", None) raw_str = handler.get_query_argument("raw", None)
direct_str = handler.get_query_argument("direct", None)
true_values = ['y', 'yes', 't', 'true', 'on', '1']
if isinstance(direct_str, str):
try:
self.direct = (direct_str.lower() in true_values)
except ValueError as e:
logger.info(e)
if isinstance(raw_str, str): if isinstance(raw_str, str):
try: try:
true_values = ['y', 'yes', 't', 'true', 'on', '1']
self.raw = (raw_str.lower() in true_values) self.raw = (raw_str.lower() in true_values)
except ValueError as e: except ValueError as e:
logger.info(e) logger.info(e)
@ -172,20 +180,21 @@ class UpstreamHandler():
elif self.provider.startswith("youtube"): elif self.provider.startswith("youtube"):
path = path.removeprefix("/") path = path.removeprefix("/")
self.upstream = providers[self.provider] + path self.upstream = providers[self.provider] + path
proxy_list = proxies.get(self.provider) if not self.direct:
if isinstance(proxy_list, list): proxy_list = proxies.get(self.provider)
futures = [] if isinstance(proxy_list, list):
for current in proxy_list: futures = []
future = asyncio.create_task(self.test_socks(current)) for current in proxy_list:
futures.append(future) future = asyncio.create_task(self.test_socks(current))
for future in asyncio.as_completed(futures): futures.append(future)
success, current = await future for future in asyncio.as_completed(futures):
if success: success, current = await future
self.proxy = current if success:
break self.proxy = current
for future in futures: break
if not future.done(): for future in futures:
future.cancel() if not future.done():
future.cancel()
if icecast_server is not None and stream_server is not None: if icecast_server is not None and stream_server is not None:
try: try:
@ -254,10 +263,16 @@ class MainHandler(tornado.web.RequestHandler):
provider_data = await stream_providers.get_seafile(handler.upstream, handler.proxy, logger) provider_data = await stream_providers.get_seafile(handler.upstream, handler.proxy, logger)
else: else:
provider_data = await stream_providers.get_any(handler.upstream, handler.proxy, logger) provider_data = await stream_providers.get_any(handler.upstream, handler.proxy, logger)
proxied = await handler.proxy.proxy_url([(provider_data.upstream(), provider_data.proxy_ctype()), provider_data.thumbnail()])
video_info = {} video_info = {}
video_info["upstream"] = proxied[0] if handler.direct:
video_info["poster"] = proxied[1] video_info["upstream"] = provider_data.upstream()
video_info["poster"] = provider_data.thumbnail()
else:
proxied = await handler.proxy.proxy_url([(provider_data.upstream(), provider_data.proxy_ctype()), provider_data.thumbnail()])
video_info["upstream"] = proxied[0]
video_info["poster"] = proxied[1]
video_info["ctype"] = provider_data.ctype() video_info["ctype"] = provider_data.ctype()
meta = provider_data.meta() meta = provider_data.meta()
title = provider_data.title() title = provider_data.title()