From 20152a6316101c50459244930b8d9dad1ed822f5 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Thu, 24 Sep 2020 18:50:54 -0700 Subject: Specify video height in html so page doesn't shift down after load Use true video height extracted from youtube to handle videos shorter than their quality size. (e.g. widescreen videos) --- youtube/watch.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'youtube/watch.py') diff --git a/youtube/watch.py b/youtube/watch.py index cedf632..a4612a5 100644 --- a/youtube/watch.py +++ b/youtube/watch.py @@ -28,20 +28,21 @@ def get_video_sources(info): max_resolution = 360 else: max_resolution = settings.default_resolution - for format in info['formats']: - if not all(format[attr] for attr in ('height', 'width', 'ext', 'url')): + for fmt in info['formats']: + if not all(fmt[attr] for attr in ('quality', 'width', 'ext', 'url')): continue - if format['acodec'] and format['vcodec'] and format['height'] <= max_resolution: + if fmt['acodec'] and fmt['vcodec'] and fmt['height'] <= max_resolution: video_sources.append({ - 'src': format['url'], - 'type': 'video/' + format['ext'], - 'height': format['height'], - 'width': format['width'], + 'src': fmt['url'], + 'type': 'video/' + fmt['ext'], + 'quality': fmt['quality'], + 'height': fmt['height'], + 'width': fmt['width'], }) #### order the videos sources so the preferred resolution is first ### - video_sources.sort(key=lambda source: source['height'], reverse=True) + video_sources.sort(key=lambda source: source['quality'], reverse=True) return video_sources -- cgit v1.2.3