From 3c83946b4ba5a8e3c07bd105f2bb3855d8644d0c Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Thu, 13 May 2021 16:14:57 +0200 Subject: [PATCH] maxheight and maxwidth dynamic --- stream.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/stream.py b/stream.py index ba72847..1999a3c 100755 --- a/stream.py +++ b/stream.py @@ -190,8 +190,33 @@ class MainHandler(tornado.web.RequestHandler): self.set_status(404) self.write("HTML template missing.") def handle_embed(self, provider): - max_width = self.get_query_argument("maxwidth", "320") - max_height = self.get_query_argument("maxheight", "180") + width = self.get_query_argument("maxwidth") + height = self.get_query_argument("maxheight") + if isinstance(width, str) and isinstance(height, str): + pass + if isinstance(width, str): + try: + width_num = (int(width) // 16) * 16 + except Exception: + width = "320" + height = "180" + else: + height_num = (width_num * 9) / 16 + height = str(height_num) + width = str(width_num) + elif isinstance(height, str): + try: + height_num = (int(height) // 9) * 9 + except Exception: + width = "320" + height = "180" + else: + width_num = (height_num * 16) / 9 + width = str(width_num) + height = str(height_num) + else: + width = "320" + height = "180" origin = self.request.path if stream_server is not None: origin = f'{stream_server}{self.request.path}'