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}'