diff options
| author | Omar Roth <omarroth@hotmail.com> | 2018-07-29 10:56:52 -0500 |
|---|---|---|
| committer | Omar Roth <omarroth@hotmail.com> | 2018-07-29 10:56:52 -0500 |
| commit | 2b911aabc4ec656eaea88eb60a8ad9f65f3ae89d (patch) | |
| tree | 12f0d0b0f3542c36c5ee8ffb623218ced5d308c8 /src | |
| parent | 6aeb508f291eda935cc7077d7faaf9034d5c3270 (diff) | |
| download | invidious-2b911aabc4ec656eaea88eb60a8ad9f65f3ae89d.tar.gz invidious-2b911aabc4ec656eaea88eb60a8ad9f65f3ae89d.tar.bz2 invidious-2b911aabc4ec656eaea88eb60a8ad9f65f3ae89d.zip | |
Fix comments endpoint for videos that have no comments
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious.cr | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/invidious.cr b/src/invidious.cr index 7fdfbcfe..1195417f 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -563,12 +563,21 @@ get "/api/v1/comments/:id" do |env| else body = 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 + end comments = JSON.build do |json| json.object do if 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_i json.field "commentCount", comment_count end |
