aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/utils.py
diff options
context:
space:
mode:
authorZenon Mousmoulas <zmousm@users.noreply.github.com>2022-03-04 23:52:48 +0200
committerGitHub <noreply@github.com>2022-03-04 13:52:48 -0800
commit27231526ae4dd3b0619d25a2e9d73186c1197c2f (patch)
treecbaff7cb8e0f5b877689b35264037e71f091ab83 /yt_dlp/utils.py
parent50e93e03a7ca6ae35a319ea310104f7d6d91eee3 (diff)
downloadhypervideo-pre-27231526ae4dd3b0619d25a2e9d73186c1197c2f.tar.lz
hypervideo-pre-27231526ae4dd3b0619d25a2e9d73186c1197c2f.tar.xz
hypervideo-pre-27231526ae4dd3b0619d25a2e9d73186c1197c2f.zip
[ant1newsgr] Add extractor (#1982)
Authored by: zmousm
Diffstat (limited to 'yt_dlp/utils.py')
-rw-r--r--yt_dlp/utils.py22
1 files changed, 22 insertions, 0 deletions
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: