diff options
author | coletdjnz <coletdjnz@protonmail.com> | 2022-09-09 12:34:39 +1200 |
---|---|---|
committer | coletdjnz <coletdjnz@protonmail.com> | 2022-09-09 12:34:39 +1200 |
commit | 3ffb2f5bea02ad353411981d342e8db79d57fb88 (patch) | |
tree | 30dd6458cea2ccf53a982862b06c4eb96d93566b | |
parent | ae1035646a6be09c2aed3e22eb8910f341ddacfe (diff) | |
download | hypervideo-pre-3ffb2f5bea02ad353411981d342e8db79d57fb88.tar.lz hypervideo-pre-3ffb2f5bea02ad353411981d342e8db79d57fb88.tar.xz hypervideo-pre-3ffb2f5bea02ad353411981d342e8db79d57fb88.zip |
[extractor/youtube] Fix video like count extraction
Support new combined button layout
Authored by: coletdjnz
-rw-r--r-- | yt_dlp/extractor/youtube.py | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py index 3ca189e44..6c4e995b8 100644 --- a/yt_dlp/extractor/youtube.py +++ b/yt_dlp/extractor/youtube.py @@ -3911,19 +3911,24 @@ class YoutubeIE(YoutubeBaseInfoExtractor): vpir, lambda x: x['videoActions']['menuRenderer']['topLevelButtons'], list) or []): - tbr = tlb.get('toggleButtonRenderer') or {} - for getter, regex in [( - lambda x: x['defaultText']['accessibility']['accessibilityData'], - r'(?P<count>[\d,]+)\s*(?P<type>(?:dis)?like)'), ([ - lambda x: x['accessibility'], - lambda x: x['accessibilityData']['accessibilityData'], - ], r'(?P<type>(?:dis)?like) this video along with (?P<count>[\d,]+) other people')]: - label = (try_get(tbr, getter, dict) or {}).get('label') - if label: - mobj = re.match(regex, label) - if mobj: - info[mobj.group('type') + '_count'] = str_to_int(mobj.group('count')) - break + tbrs = variadic( + traverse_obj( + tlb, 'toggleButtonRenderer', + ('segmentedLikeDislikeButtonRenderer', ..., 'toggleButtonRenderer'), + default=[])) + for tbr in tbrs: + for getter, regex in [( + lambda x: x['defaultText']['accessibility']['accessibilityData'], + r'(?P<count>[\d,]+)\s*(?P<type>(?:dis)?like)'), ([ + lambda x: x['accessibility'], + lambda x: x['accessibilityData']['accessibilityData'], + ], r'(?P<type>(?:dis)?like) this video along with (?P<count>[\d,]+) other people')]: + label = (try_get(tbr, getter, dict) or {}).get('label') + if label: + mobj = re.match(regex, label) + if mobj: + info[mobj.group('type') + '_count'] = str_to_int(mobj.group('count')) + break sbr_tooltip = try_get( vpir, lambda x: x['sentimentBar']['sentimentBarRenderer']['tooltip']) if sbr_tooltip: |