diff --git a/locales/en-US.json b/locales/en-US.json index d05c0d165..20e400e21 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -238,6 +238,7 @@ "This channel does not exist.": "This channel does not exist.", "Could not get channel info.": "Could not get channel info.", "Could not fetch comments": "Could not fetch comments", + "Comments are turned off": "Comments are turned off", "comments_view_x_replies": "View {{count}} reply", "comments_view_x_replies_plural": "View {{count}} replies", "`x` ago": "`x` ago", diff --git a/src/invidious/comments/youtube.cr b/src/invidious/comments/youtube.cr index 78a569ab0..47bdfaa5b 100644 --- a/src/invidious/comments/youtube.cr +++ b/src/invidious/comments/youtube.cr @@ -94,17 +94,45 @@ module Invidious::Comments if !contents if format == "json" - return {"comments" => [] of String}.to_json + return { + "comments" => [] of String, + "commentCount" => 0, + "commentsDisabled" => true, + }.to_json else - return {"contentHtml" => "", "commentCount" => 0}.to_json + return { + "contentHtml" => Frontend::Comments.template_youtube_disabled(locale), + "commentCount" => 0, + "commentsDisabled" => true, + }.to_json end end continuation_item_renderer = nil + has_message_renderer = false contents.as_a.reject! do |item| if item["continuationItemRenderer"]? continuation_item_renderer = item["continuationItemRenderer"] true + elsif item["messageRenderer"]? + has_message_renderer = true + true + end + end + + if has_message_renderer || contents.as_a.empty? + if format == "json" + return { + "comments" => [] of String, + "commentCount" => 0, + "commentsDisabled" => true, + }.to_json + else + return { + "contentHtml" => Frontend::Comments.template_youtube_disabled(locale), + "commentCount" => 0, + "commentsDisabled" => true, + }.to_json end end diff --git a/src/invidious/frontend/comments_youtube.cr b/src/invidious/frontend/comments_youtube.cr index 89d3caeff..f0c6ff98e 100644 --- a/src/invidious/frontend/comments_youtube.cr +++ b/src/invidious/frontend/comments_youtube.cr @@ -1,6 +1,14 @@ module Invidious::Frontend::Comments extend self + def template_youtube_disabled(locale) + <<-END_HTML +
+

#{I18n.translate(locale, "Comments are turned off")}

+
+ END_HTML + end + def template_youtube(comments, locale, thin_mode, is_replies = false) String.build do |html| root = comments["comments"].as_a