Skip to content

Commit

Permalink
[YouTube] Fix like_count extraction using likeButtonViewModel
Browse files Browse the repository at this point in the history
* also fix various tests
* TODO: check against yt-dlp tests
  • Loading branch information
dirkf committed Jan 15, 2024
1 parent 4ff8403 commit 95a7e9b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions youtube_dl/extractor/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@
mimetype2ext,
NO_DEFAULT,
parse_codecs,
parse_count,
parse_duration,
parse_qs,
qualities,
remove_start,
smuggle_url,
str_or_none,
str_to_int,
T,
traverse_obj,
try_get,
txt_or_none,
Expand Down Expand Up @@ -1248,7 +1250,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'title': 'IMG 3456',
'description': '',
'upload_date': '20170613',
'uploader': 'ElevageOrVert',
'uploader': "l'Or Vert asbl",
'uploader_id': '@ElevageOrVert',
},
'params': {
Expand Down Expand Up @@ -2393,6 +2395,14 @@ def chapter_time(mmlir):
'like_count': str_to_int(like_count),
'dislike_count': str_to_int(dislike_count),
})
else:
info['like_count'] = traverse_obj(vpir, (
'videoActions', 'menuRenderer', 'topLevelButtons', Ellipsis,
'segmentedLikeDislikeButtonViewModel', 'likeButtonViewModel', 'likeButtonViewModel',
'toggleButtonViewModel', 'toggleButtonViewModel', 'defaultButtonViewModel',
'buttonViewModel', (('title', ('accessibilityText', T(lambda s: s.split()), Ellipsis))), T(parse_count)),
get_all=False)

vsir = content.get('videoSecondaryInfoRenderer')
if vsir:
rows = try_get(
Expand Down Expand Up @@ -2507,7 +2517,7 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
'playlist_mincount': 94,
'info_dict': {
'id': 'UCqj7Cz7revf5maW9g5pgNcg',
'title': 'Igor Kleiner - Playlists',
'title': r're:Igor Kleiner(?: Ph\.D\.)? - Playlists',
'description': 'md5:be97ee0f14ee314f1f002cf187166ee2',
'uploader': 'Igor Kleiner',
'uploader_id': '@IgorDataScience',
Expand All @@ -2518,7 +2528,7 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
'playlist_mincount': 94,
'info_dict': {
'id': 'UCqj7Cz7revf5maW9g5pgNcg',
'title': 'Igor Kleiner - Playlists',
'title': r're:Igor Kleiner(?: Ph\.D\.)? - Playlists',
'description': 'md5:be97ee0f14ee314f1f002cf187166ee2',
'uploader': 'Igor Kleiner',
'uploader_id': '@IgorDataScience',
Expand Down Expand Up @@ -2630,7 +2640,7 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
'url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w/channels',
'info_dict': {
'id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
'title': 'lex will - Channels',
'title': r're:lex will - (?:Home|Channels)',
'description': 'md5:2163c5d0ff54ed5f598d6a7e6211e488',
'uploader': 'lex will',
'uploader_id': '@lexwill718',
Expand Down

0 comments on commit 95a7e9b

Please sign in to comment.