From 27231526ae4dd3b0619d25a2e9d73186c1197c2f Mon Sep 17 00:00:00 2001 From: Zenon Mousmoulas Date: Fri, 4 Mar 2022 23:52:48 +0200 Subject: [ant1newsgr] Add extractor (#1982) Authored by: zmousm --- yt_dlp/utils.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'yt_dlp/utils.py') diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py index be0c69d8f..87463c999 100644 --- a/yt_dlp/utils.py +++ b/yt_dlp/utils.py @@ -5271,6 +5271,28 @@ def join_nonempty(*values, delim='-', from_dict=None): return delim.join(map(str, filter(None, values))) +def scale_thumbnails_to_max_format_width(formats, thumbnails, url_width_re): + """ + Find the largest format dimensions in terms of video width and, for each thumbnail: + * Modify the URL: Match the width with the provided regex and replace with the former width + * Update dimensions + + This function is useful with video services that scale the provided thumbnails on demand + """ + _keys = ('width', 'height') + max_dimensions = max( + [tuple(format.get(k) or 0 for k in _keys) for format in formats], + default=(0, 0)) + if not max_dimensions[0]: + return thumbnails + return [ + merge_dicts( + {'url': re.sub(url_width_re, str(max_dimensions[0]), thumbnail['url'])}, + dict(zip(_keys, max_dimensions)), thumbnail) + for thumbnail in thumbnails + ] + + def parse_http_range(range): """ Parse value of "Range" or "Content-Range" HTTP header into tuple. """ if not range: -- cgit v1.2.3