From 97972d6fa3bdbe4a02589345373c958e7b2f9c22 Mon Sep 17 00:00:00 2001 From: Astound Date: Mon, 22 Jan 2024 06:35:46 +0800 Subject: Fix like count extraction --- youtube/yt_data_extract/watch_extraction.py | 32 ++++++++++++++++++----------- 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'youtube/yt_data_extract/watch_extraction.py') diff --git a/youtube/yt_data_extract/watch_extraction.py b/youtube/yt_data_extract/watch_extraction.py index b943d35..e09e2d3 100644 --- a/youtube/yt_data_extract/watch_extraction.py +++ b/youtube/yt_data_extract/watch_extraction.py @@ -140,11 +140,12 @@ def _extract_likes_dislikes(renderer_content): ['defaultText', 'accessibility', 'accessibilityData', 'label'], ['accessibility', 'label'], ['accessibilityData', 'accessibilityData', 'label'], + ['accessibilityText'], )) # this count doesn't have all the digits, it's like 53K for instance - dumb_count = extract_int(extract_str(deep_get( - toggle_button_renderer, 'defaultText'))) + dumb_count = extract_int(extract_str(multi_get( + toggle_button_renderer, ['defaultText', 'title']))) # The accessibility text will be "No likes" or "No dislikes" or # something like that, but dumb count will be 0 @@ -168,16 +169,23 @@ def _extract_likes_dislikes(renderer_content): info['dislike_count'] = count elif 'slimMetadataButtonRenderer' in button: button_renderer = button['slimMetadataButtonRenderer'] - liberal_update(info, 'like_count', extract_button_count(deep_get( - button_renderer, 'button', - 'segmentedLikeDislikeButtonRenderer', - 'likeButton', 'toggleButtonRenderer' - ))) - liberal_update(info, 'dislike_count',extract_button_count(deep_get( - button_renderer, 'button', - 'segmentedLikeDislikeButtonRenderer', - 'dislikeButton', 'toggleButtonRenderer' - ))) + liberal_update(info, 'like_count', extract_button_count( + multi_deep_get(button_renderer, + ['button', 'segmentedLikeDislikeButtonRenderer', + 'likeButton', 'toggleButtonRenderer'], + ['button', 'segmentedLikeDislikeButtonViewModel', + 'likeButtonViewModel', 'likeButtonViewModel', + 'toggleButtonViewModel', 'toggleButtonViewModel', + 'defaultButtonViewModel', 'buttonViewModel'] + ) + )) + '''liberal_update(info, 'dislike_count', extract_button_count( + deep_get( + button_renderer, 'button', + 'segmentedLikeDislikeButtonRenderer', + 'dislikeButton', 'toggleButtonRenderer' + ) + ))''' return info def _extract_from_owner_renderer(renderer_content): -- cgit v1.2.3