From 82029e2537aa5f755448d08895eb465d3363f26d Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Sun, 9 May 2021 18:49:40 +0200 Subject: [PATCH] fix path to html --- Dockerfile | 1 + stream.py | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 93ae53e..bd70ca4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,7 @@ RUN ["apk", "add", "--no-cache", "--repository", "https://dl-cdn.alpinelinux.org RUN ["mkdir", "/app"] COPY ["stream.py", "/app/stream.py"] COPY ["sources.py", "/app/sources.py"] +COPY ["index.html", "/app/index.html"] RUN ["chmod", "-R", "755", "/app"] COPY ["tv.json", "/app/tv.json"] RUN ["python3", "/app/sources.py"] diff --git a/stream.py b/stream.py index 38c7a42..5de699c 100755 --- a/stream.py +++ b/stream.py @@ -50,9 +50,11 @@ if icecast_server is not None and stream_server is not None: playlist += stream_server + key + "\n" template = None -with open("index.html", "r") as f: - template = tornado.template.Template(f.read().strip()) - +try: + with open("/app/index.html", "r") as f: + template = tornado.template.Template(f.read().strip()) +except Exception as e: + print(e) def get_proxy_url(proxy, current, path): data = {} @@ -106,13 +108,17 @@ class MainHandler(tornado.web.RequestHandler): else: self.set_status(404) if write: - self.write("stream not found") + 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) - + if template is not None: + stream_path = f'{self.request.path}?provider={provider}' + rendered = template.generate(stream=stream_path) + self.write(rendered) + else: + self.set_status(404) + self.write("HTML template missing.") + def handle_stream(self, provider, write): upstream = None proxy = None @@ -139,7 +145,7 @@ class MainHandler(tornado.web.RequestHandler): if upstream is None: self.set_status(404) if write: - self.write("stream not found") + self.write("Stream not found.") else: data = rewrite(upstream, provider) if data is None: