From a9e86cecf5dcc7c5b685bc80045b85cf90bd922b Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Fri, 21 Jun 2019 20:25:31 -0500 Subject: [PATCH] Fix comment extractor --- src/invidious/comments.cr | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index 7f1b010d..51c092ac 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -114,7 +114,8 @@ def fetch_youtube_comments(id, db, continuation, proxies, format, locale, thin_m comments = JSON.build do |json| json.object do if body["header"]? - comment_count = body["header"]["commentsHeaderRenderer"]["countText"]["simpleText"].as_s.delete("Comments,").to_i + comment_count = body["header"]["commentsHeaderRenderer"]["countText"]["runs"][0]? + .try &.["text"].as_s.gsub(/\D/, "").to_i? || 0 json.field "commentCount", comment_count end @@ -140,9 +141,7 @@ def fetch_youtube_comments(id, db, continuation, proxies, format, locale, thin_m content_html = node_comment["contentText"]["simpleText"]?.try &.as_s.rchop('\ufeff').try { |block| HTML.escape(block) }.to_s || content_to_comment_html(node_comment["contentText"]["runs"].as_a).try &.to_s || "" - - author = node_comment["authorText"]?.try &.["simpleText"] - author ||= "" + author = node_comment["authorText"]?.try &.["simpleText"]? || "" json.field "author", author json.field "authorThumbnails" do @@ -193,13 +192,7 @@ def fetch_youtube_comments(id, db, continuation, proxies, format, locale, thin_m end if node_replies && !response["commentRepliesContinuation"]? - reply_count = node_replies["moreText"]["simpleText"].as_s.delete("View all reply replies,") - if reply_count.empty? - reply_count = 1 - else - reply_count = reply_count.try &.to_i? - reply_count ||= 1 - end + reply_count = node_replies["moreText"]["runs"][0]?.try &.["text"].as_s.gsub(/\D/, "").to_i? || 1 continuation = node_replies["continuations"]?.try &.as_a[0]["nextContinuationData"]["continuation"].as_s continuation ||= ""