summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2022-09-08 00:06:58 +0200
committerSamantaz Fox <coding@samantaz.fr>2022-10-31 20:30:30 +0100
commit83795c245aace771fb73936b22d3de7ced0df9df (patch)
tree8c14fa7baa7af4c31adb892643ee96a8ffb1347c /src
parentd659a451d6dece62dbb091a958083c8a347da5b1 (diff)
downloadinvidious-83795c245aace771fb73936b22d3de7ced0df9df.tar.gz
invidious-83795c245aace771fb73936b22d3de7ced0df9df.tar.bz2
invidious-83795c245aace771fb73936b22d3de7ced0df9df.zip
videos: Support the new like button's structure
Diffstat (limited to 'src')
-rw-r--r--src/invidious/videos/parser.cr12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/invidious/videos/parser.cr b/src/invidious/videos/parser.cr
index ff5d15de..701c4e77 100644
--- a/src/invidious/videos/parser.cr
+++ b/src/invidious/videos/parser.cr
@@ -227,11 +227,21 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
.try &.dig?("videoActions", "menuRenderer", "topLevelButtons")
if toplevel_buttons
- likes_button = toplevel_buttons.as_a
+ likes_button = toplevel_buttons.try &.as_a
.find(&.dig?("toggleButtonRenderer", "defaultIcon", "iconType").=== "LIKE")
.try &.["toggleButtonRenderer"]
+ # New format as of september 2022
+ likes_button ||= toplevel_buttons.try &.as_a
+ .find(&.["segmentedLikeDislikeButtonRenderer"]?)
+ .try &.dig?(
+ "segmentedLikeDislikeButtonRenderer",
+ "likeButton", "toggleButtonRenderer"
+ )
+
if likes_button
+ # Note: The like count from `toggledText` is off by one, as it would
+ # represent the new like count in the event where the user clicks on "like".
likes_txt = (likes_button["defaultText"]? || likes_button["toggledText"]?)
.try &.dig?("accessibility", "accessibilityData", "label")
likes = likes_txt.as_s.gsub(/\D/, "").to_i64? if likes_txt