diff options
| author | Omar Roth <omarroth@protonmail.com> | 2019-06-21 20:25:31 -0500 |
|---|---|---|
| committer | Omar Roth <omarroth@protonmail.com> | 2019-06-21 20:25:31 -0500 |
| commit | a9e86cecf5dcc7c5b685bc80045b85cf90bd922b (patch) | |
| tree | 96111190e0767d7c07b8a3148a1e76e6aa062e45 | |
| parent | 5773b1c3e54c18a4ad84543fda89ea176b62d5c8 (diff) | |
| download | invidious-a9e86cecf5dcc7c5b685bc80045b85cf90bd922b.tar.gz invidious-a9e86cecf5dcc7c5b685bc80045b85cf90bd922b.tar.bz2 invidious-a9e86cecf5dcc7c5b685bc80045b85cf90bd922b.zip | |
Fix comment extractor
| -rw-r--r-- | src/invidious/comments.cr | 15 |
1 files 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 ||= "" |
