Skip to content

Commit 54558e0

Browse files
committed
[youtube] Improve stretch extraction and fix stretched ratio calculation (closes ytdl-org#28769)
1 parent 7c52395 commit 54558e0

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

youtube_dl/extractor/youtube.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,11 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
812812
},
813813
'skip': 'This video does not exist.',
814814
},
815+
{
816+
# Video with incomplete 'yt:stretch=16:'
817+
'url': 'https://www.youtube.com/watch?v=FRhJzUSJbGI',
818+
'only_matching': True,
819+
},
815820
{
816821
# Video licensed under Creative Commons
817822
'url': 'https://www.youtube.com/watch?v=M4gD1WSo5mA',
@@ -1717,13 +1722,16 @@ def feed_entry(name):
17171722
for m in re.finditer(self._meta_regex('og:video:tag'), webpage)]
17181723
for keyword in keywords:
17191724
if keyword.startswith('yt:stretch='):
1720-
w, h = keyword.split('=')[1].split(':')
1721-
w, h = int(w), int(h)
1722-
if w > 0 and h > 0:
1723-
ratio = w / h
1724-
for f in formats:
1725-
if f.get('vcodec') != 'none':
1726-
f['stretched_ratio'] = ratio
1725+
mobj = re.search(r'(\d+)\s*:\s*(\d+)', keyword)
1726+
if mobj:
1727+
# NB: float is intentional for forcing float division
1728+
w, h = (float(v) for v in mobj.groups())
1729+
if w > 0 and h > 0:
1730+
ratio = w / h
1731+
for f in formats:
1732+
if f.get('vcodec') != 'none':
1733+
f['stretched_ratio'] = ratio
1734+
break
17271735

17281736
thumbnails = []
17291737
for container in (video_details, microformat):

0 commit comments

Comments
 (0)