diff options
author | James Taylor <user234683@users.noreply.github.com> | 2020-09-24 18:50:54 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2020-09-24 18:50:54 -0700 |
commit | 20152a6316101c50459244930b8d9dad1ed822f5 (patch) | |
tree | f2dead9aea6fddd2f0f77a8593d850305a2012c4 /youtube/watch.py | |
parent | 9f0d84ddb9e5ae67d1626bea94501ff0308efae5 (diff) | |
download | yt-local-20152a6316101c50459244930b8d9dad1ed822f5.tar.lz yt-local-20152a6316101c50459244930b8d9dad1ed822f5.tar.xz yt-local-20152a6316101c50459244930b8d9dad1ed822f5.zip |
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)
Diffstat (limited to 'youtube/watch.py')
-rw-r--r-- | youtube/watch.py | 17 |
1 files changed, 9 insertions, 8 deletions
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 |