mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-11-07 01:55:13 +00:00
[youtube:tab] Fix duration extraction for shorts (#3171)
Related: https://github.com/TeamNewPipe/NewPipe/issues/8034 Authored-by: coletdjnz
This commit is contained in:
@@ -807,6 +807,12 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
||||
description = self._get_text(renderer, 'descriptionSnippet')
|
||||
duration = parse_duration(self._get_text(
|
||||
renderer, 'lengthText', ('thumbnailOverlays', ..., 'thumbnailOverlayTimeStatusRenderer', 'text')))
|
||||
if duration is None:
|
||||
duration = parse_duration(self._search_regex(
|
||||
r'(?i)(ago)(?!.*\1)\s+(?P<duration>[a-z0-9 ,]+?)(?:\s+[\d,]+\s+views)?(?:\s+-\s+play\s+short)?$',
|
||||
traverse_obj(renderer, ('title', 'accessibility', 'accessibilityData', 'label'), default='', expected_type=str),
|
||||
video_id, default=None, group='duration'))
|
||||
|
||||
view_count = self._get_count(renderer, 'viewCountText')
|
||||
|
||||
uploader = self._get_text(renderer, 'ownerText', 'shortBylineText')
|
||||
|
||||
@@ -2644,23 +2644,23 @@ def parse_duration(s):
|
||||
m = re.match(
|
||||
r'''(?ix)(?:P?
|
||||
(?:
|
||||
[0-9]+\s*y(?:ears?)?\s*
|
||||
[0-9]+\s*y(?:ears?)?,?\s*
|
||||
)?
|
||||
(?:
|
||||
[0-9]+\s*m(?:onths?)?\s*
|
||||
[0-9]+\s*m(?:onths?)?,?\s*
|
||||
)?
|
||||
(?:
|
||||
[0-9]+\s*w(?:eeks?)?\s*
|
||||
[0-9]+\s*w(?:eeks?)?,?\s*
|
||||
)?
|
||||
(?:
|
||||
(?P<days>[0-9]+)\s*d(?:ays?)?\s*
|
||||
(?P<days>[0-9]+)\s*d(?:ays?)?,?\s*
|
||||
)?
|
||||
T)?
|
||||
(?:
|
||||
(?P<hours>[0-9]+)\s*h(?:ours?)?\s*
|
||||
(?P<hours>[0-9]+)\s*h(?:ours?)?,?\s*
|
||||
)?
|
||||
(?:
|
||||
(?P<mins>[0-9]+)\s*m(?:in(?:ute)?s?)?\s*
|
||||
(?P<mins>[0-9]+)\s*m(?:in(?:ute)?s?)?,?\s*
|
||||
)?
|
||||
(?:
|
||||
(?P<secs>[0-9]+)(?P<ms>\.[0-9]+)?\s*s(?:ec(?:ond)?s?)?\s*
|
||||
|
||||
Reference in New Issue
Block a user