rewrite width
This commit is contained in:
parent
39375d7478
commit
118ffa16f8
56
stream.py
56
stream.py
@ -190,41 +190,43 @@ class MainHandler(tornado.web.RequestHandler):
|
|||||||
self.set_status(404)
|
self.set_status(404)
|
||||||
self.write("HTML template missing.")
|
self.write("HTML template missing.")
|
||||||
def handle_embed(self, provider):
|
def handle_embed(self, provider):
|
||||||
width = self.get_query_argument("maxwidth", None)
|
width_str = self.get_query_argument("maxwidth", None)
|
||||||
height = self.get_query_argument("maxheight", None)
|
height_str = self.get_query_argument("maxheight", None)
|
||||||
if isinstance(width, str) and isinstance(height, str):
|
width = 320
|
||||||
|
height = 180
|
||||||
|
try:
|
||||||
|
if isinstance(width_str, str):
|
||||||
|
width_new = int(width_str)
|
||||||
|
if width_new > 16:
|
||||||
|
width = width_new
|
||||||
|
else:
|
||||||
|
raise ValueError("invalid width")
|
||||||
|
if isinstance(height_str, str):
|
||||||
|
height_new = int(height_str)
|
||||||
|
if height_new > 9:
|
||||||
|
height = height_new
|
||||||
|
else:
|
||||||
|
raise ValueError("invalid height")
|
||||||
|
except Exception:
|
||||||
pass
|
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:
|
else:
|
||||||
width = "320"
|
if isinstance(width_str, str) and isinstance(height_str, str):
|
||||||
height = "180"
|
pass
|
||||||
|
elif isinstance(width_str, str):
|
||||||
|
width = (width // 16) * 16
|
||||||
|
height = (width * 9) / 16
|
||||||
|
elif isinstance(height_str, str):
|
||||||
|
height = (height // 9) * 9
|
||||||
|
width = (height * 16) / 9
|
||||||
|
|
||||||
origin = self.request.path
|
origin = self.request.path
|
||||||
if stream_server is not None:
|
if stream_server is not None:
|
||||||
origin = f'{stream_server}{self.request.path}'
|
origin = f'{stream_server}{self.request.path}'
|
||||||
embed_json = {}
|
embed_json = {}
|
||||||
embed_json["version"] = "1.0"
|
embed_json["version"] = "1.0"
|
||||||
embed_json["type"] = "video"
|
embed_json["type"] = "video"
|
||||||
embed_json["width"] = max_width
|
embed_json["width"] = width
|
||||||
embed_json["height"] = max_height
|
embed_json["height"] = height
|
||||||
embed_json["html"] = str(template_embed.generate(origin=origin, provider=provider), "utf-8")
|
embed_json["html"] = str(template_embed.generate(origin=origin, provider=provider), "utf-8")
|
||||||
self.set_header("Content-Type", "application/json; charset=utf-8")
|
self.set_header("Content-Type", "application/json; charset=utf-8")
|
||||||
self.write(json.dumps(embed_json))
|
self.write(json.dumps(embed_json))
|
||||||
|
Loading…
Reference in New Issue
Block a user