diff --git a/index.html b/index.html new file mode 100644 index 0000000..f44633d --- /dev/null +++ b/index.html @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/stream.py b/stream.py index 7edfa92..38c7a42 100755 --- a/stream.py +++ b/stream.py @@ -49,6 +49,11 @@ if icecast_server is not None and stream_server is not None: playlist += f'#EXTINF:0 radio="false", {name}\n' playlist += stream_server + key + "\n" +template = None +with open("index.html", "r") as f: + template = tornado.template.Template(f.read().strip()) + + def get_proxy_url(proxy, current, path): data = {} data["upstream"] = urllib.parse.urljoin(current, path) @@ -64,7 +69,6 @@ def rewrite(current, provider): proxy = proxies_raw.get(provider) resp = requests.head(current, proxies=proxy_req) ctype = resp.headers.get("Content-Type") - print(ctype) if ctype is None: return None else: @@ -90,9 +94,29 @@ def rewrite(current, provider): class MainHandler(tornado.web.RequestHandler): def handle_any(self, write): provider = self.get_query_argument("provider", None) + render = self.get_query_argument("render", False) + if isinstance(provider, str): + if isinstance(render, str): + if render.lower() == "true": + self.handle_render(provider, write) + else: + self.handle_stream(provider, write) + else: + self.handle_stream(provider, write) + else: + self.set_status(404) + if write: + self.write("stream not found") + + def handle_render(self, provider, write): + stream_path = f'{self.request.path}?provider={provider}' + rendered = template.generate(stream=stream_path) + self.write(rendered) + + def handle_stream(self, provider, write): upstream = None proxy = None - if provider is not None and provider in providers.keys(): + if provider in providers.keys(): proxy = proxies.get(provider) src = providers[provider] + self.request.path try: