Invidious is an alternative front-end to YouTube
Fix comments endpoint for videos that have no comments
Omar Roth2b911aabc4ec
diff --git a/src/invidious.cr b/src/invidious.crindex 7fdfbcfe..1195417f 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -563,12 +563,21 @@ get "/api/v1/comments/:id" do |env|elsebody = response["itemSectionContinuation"]end- contents = body["contents"]+ contents = body["contents"]?+ if !contents+ env.response.content_type = "application/json"++ if format == "json"+ next {"comments" => [] of String}.to_json+ else+ next {"content_html" => ""}.to_json+ end+ endcomments = JSON.build do |json|json.object doif body["header"]?- comment_count = body["header"]["commentsHeaderRenderer"]["countText"]["simpleText"].as_s.rchop(" Comment").delete("s,").to_i+ comment_count = body["header"]["commentsHeaderRenderer"]["countText"]["simpleText"].as_s.delete("Comments,").to_ijson.field "commentCount", comment_countend