diff --git a/backend/stream.py b/backend/stream.py index 1dd8bde..b00102b 100755 --- a/backend/stream.py +++ b/backend/stream.py @@ -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,20 +180,21 @@ class UpstreamHandler(): elif self.provider.startswith("youtube"): path = path.removeprefix("/") self.upstream = providers[self.provider] + path - proxy_list = proxies.get(self.provider) - if isinstance(proxy_list, list): - futures = [] - for current in proxy_list: - future = asyncio.create_task(self.test_socks(current)) - futures.append(future) - for future in asyncio.as_completed(futures): - success, current = await future - if success: - self.proxy = current - break - for future in futures: - if not future.done(): - future.cancel() + if not self.direct: + proxy_list = proxies.get(self.provider) + if isinstance(proxy_list, list): + futures = [] + for current in proxy_list: + future = asyncio.create_task(self.test_socks(current)) + futures.append(future) + for future in asyncio.as_completed(futures): + success, current = await future + if success: + self.proxy = current + break + for future in futures: + if not future.done(): + future.cancel() if icecast_server is not None and stream_server is not None: try: @@ -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 = {} - video_info["upstream"] = proxied[0] - video_info["poster"] = proxied[1] + 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()