From 5a194507a0e777a33b98318d212d66bcddebc338 Mon Sep 17 00:00:00 2001 From: MMaker Date: Wed, 26 Feb 2025 00:31:51 -0500 Subject: [PATCH] Get correct video dimensions --- app.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app.py b/app.py index d202673..3d92c31 100644 --- a/app.py +++ b/app.py @@ -173,6 +173,12 @@ def allow_download(params): return False return True +def get_video_resolution(params): + if not params: + return None, None + video = params['media']['domand']['videos'][0] + return video['width'], video['height'] + def get_video_quality(params, quality_level_threshold=3): """Get the code of the best video quality available (optionally below a certain threshold)""" videos = params['media']['domand']['videos'] @@ -275,6 +281,7 @@ def proxy(video_id): params["video"]["thumbnail"].get("middleUrl") or params["video"]["thumbnail"].get("url") ) if params else None + video_width, video_height = get_video_resolution(params) if params else (None, None) download_allowed = allow_download(params) if params else False video_quality = get_video_quality(params) if params else None @@ -291,8 +298,6 @@ def proxy(video_id): cdn_video_url = get_cdn_url(video_id) og_tags = soup.find_all("meta", property=lambda x: x) - og_video_width = None - og_video_height = None for tag in og_tags: if 'data-server' in tag.attrs: del tag.attrs['data-server'] @@ -302,21 +307,16 @@ def proxy(video_id): # Fix video URL if tag.get("property") == "og:video:url" or tag.get("property") == "og:video:secure_url": tag["content"] = cdn_video_url - # Set vars - if tag.get("property") == "og:video:width": - og_video_width = tag.get("content") - if tag.get("property") == "og:video:height": - og_video_height = tag.get("content") og_tags_str = "\n".join(str(tag) for tag in og_tags if tag.get("property") not in ["og:site_name"]) og_tags_str += '\n' og_tags_str += '\n' og_tags_str += '\n' og_tags_str += f'\n' - if og_video_width: - og_tags_str += f'\n' - if og_video_height: - og_tags_str += f'\n' + if video_width: + og_tags_str += f'\n' + if video_height: + og_tags_str += f'\n' og_tags_str += '\n' og_tags_str += f'\n' html_response = f"""