diff --git a/stream.py b/stream.py index 3bd885e..0cac783 100755 --- a/stream.py +++ b/stream.py @@ -27,6 +27,7 @@ for key in proxies: playlist = None icecast_server = os.environ.get("ICECAST_SERVER") stream_server = os.environ.get("STREAM_SERVER") + if icecast_server is not None and stream_server is not None: with open("/app/sources.json", "r") as f: data = json.loads(f.read()) @@ -43,7 +44,7 @@ if icecast_server is not None and stream_server is not None: playlist += stream_server + key + "\n" class MainHandler(tornado.web.RequestHandler): - def handle_any(self): + def handle_any(self, write): provider = self.get_query_argument("provider", None) endpoint = None if provider is not None and provider in providers.keys(): @@ -67,13 +68,15 @@ class MainHandler(tornado.web.RequestHandler): print(str(e)) endpoint = None if endpoint is None: - self.set_status(404, reason="stream not found") + self.set_status(404) + if write: + self.write("stream not found") else: self.redirect(endpoint, status=303) def get(self): - self.handle_any() + self.handle_any(True) def head(self): - self.handle_any() + self.handle_any(False) class FileHandler(tornado.web.RequestHandler): def get(self):