Skip to content

Commit 5ceeefa

Browse files
add support for new likes format
1 parent e8a3698 commit 5ceeefa

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/invidious/videos/parser.cr

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,18 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
266266
.try &.dig?("videoActions", "menuRenderer", "topLevelButtons")
267267

268268
if toplevel_buttons
269-
likes_button = toplevel_buttons.try &.as_a
269+
# New Format as of december 2023
270+
likes_button = toplevel_buttons.dig?(0,
271+
"segmentedLikeDislikeButtonViewModel",
272+
"likeButtonViewModel",
273+
"likeButtonViewModel",
274+
"toggleButtonViewModel",
275+
"toggleButtonViewModel",
276+
"defaultButtonViewModel",
277+
"buttonViewModel"
278+
)
279+
280+
likes_button ||= toplevel_buttons.try &.as_a
270281
.find(&.dig?("toggleButtonRenderer", "defaultIcon", "iconType").=== "LIKE")
271282
.try &.["toggleButtonRenderer"]
272283

@@ -279,9 +290,10 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
279290
)
280291

281292
if likes_button
293+
likes_txt = likes_button.dig?("accessibilityText")
282294
# Note: The like count from `toggledText` is off by one, as it would
283295
# represent the new like count in the event where the user clicks on "like".
284-
likes_txt = (likes_button["defaultText"]? || likes_button["toggledText"]?)
296+
likes_txt ||= (likes_button["defaultText"]? || likes_button["toggledText"]?)
285297
.try &.dig?("accessibility", "accessibilityData", "label")
286298
likes = likes_txt.as_s.gsub(/\D/, "").to_i64? if likes_txt
287299

0 commit comments

Comments
 (0)