summary refs log tree commit diff
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2021-04-17 02:27:54 +0700
committerSergey M․ <dstftw@gmail.com>2021-04-17 02:27:54 +0700
commit54558e0baa4d62a94af105cd1d7f8abcbd16b468 (patch)
tree2b6959c29014fcc824e7f74db3fd4b119e36ea19
parent7c5239547928079513b65f62e4c84aea21ce76e6 (diff)
downloadyoutube-dl-54558e0baa4d62a94af105cd1d7f8abcbd16b468.tar.gz
youtube-dl-54558e0baa4d62a94af105cd1d7f8abcbd16b468.tar.xz
youtube-dl-54558e0baa4d62a94af105cd1d7f8abcbd16b468.zip
[youtube] Improve stretch extraction and fix stretched ratio calculation (closes #28769)
-rw-r--r--youtube_dl/extractor/youtube.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py
index b6945570f..75751d5a6 100644
--- a/youtube_dl/extractor/youtube.py
+++ b/youtube_dl/extractor/youtube.py
@@ -813,6 +813,11 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
             'skip': 'This video does not exist.',
         },
         {
+            # Video with incomplete 'yt:stretch=16:'
+            'url': 'https://www.youtube.com/watch?v=FRhJzUSJbGI',
+            'only_matching': True,
+        },
+        {
             # Video licensed under Creative Commons
             'url': 'https://www.youtube.com/watch?v=M4gD1WSo5mA',
             'info_dict': {
@@ -1717,13 +1722,16 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
                 for m in re.finditer(self._meta_regex('og:video:tag'), webpage)]
         for keyword in keywords:
             if keyword.startswith('yt:stretch='):
-                w, h = keyword.split('=')[1].split(':')
-                w, h = int(w), int(h)
-                if w > 0 and h > 0:
-                    ratio = w / h
-                    for f in formats:
-                        if f.get('vcodec') != 'none':
-                            f['stretched_ratio'] = ratio
+                mobj = re.search(r'(\d+)\s*:\s*(\d+)', keyword)
+                if mobj:
+                    # NB: float is intentional for forcing float division
+                    w, h = (float(v) for v in mobj.groups())
+                    if w > 0 and h > 0:
+                        ratio = w / h
+                        for f in formats:
+                            if f.get('vcodec') != 'none':
+                                f['stretched_ratio'] = ratio
+                        break
 
         thumbnails = []
         for container in (video_details, microformat):