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.valid = False
self.proxy = ProxyElem(None)
self.direct = False
self.upstream = None
async def test_socks(self, proxy):
if not hasattr(proxy, "proxy") or not isinstance(proxy.proxy, str):
@ -158,9 +159,16 @@ class UpstreamHandler():
async def setup(self, handler):
self.provider = handler.get_query_argument("provider", 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):
try:
true_values = ['y', 'yes', 't', 'true', 'on', '1']
self.raw = (raw_str.lower() in true_values)
except ValueError as e:
logger.info(e)
@ -172,6 +180,7 @@ class UpstreamHandler():
elif self.provider.startswith("youtube"):
path = path.removeprefix("/")
self.upstream = providers[self.provider] + path
if not self.direct:
proxy_list = proxies.get(self.provider)
if isinstance(proxy_list, list):
futures = []
@ -254,10 +263,16 @@ class MainHandler(tornado.web.RequestHandler):
provider_data = await stream_providers.get_seafile(handler.upstream, handler.proxy, logger)
else:
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 = {}
if handler.direct:
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()
meta = provider_data.meta()
title = provider_data.title()