From feff91a225a589f0f5b89dddbe4b9570166069fc Mon Sep 17 00:00:00 2001 From: Alex DevTech Date: Thu, 30 Jul 2026 18:08:46 -0700 Subject: [PATCH] feat: show "Comments are turned off" message when YouTube comments are disabled Closes #1092 - Detect messageRenderer in YouTube API response when comments are disabled - Show a localized "Comments are turned off" message in HTML response - Add "commentsDisabled: true" flag to both JSON and HTML API responses - Add I18n locale string for the disabled message - Handle both empty continuationItems and messageRenderer presence --- locales/en-US.json | 1 + src/invidious/comments/youtube.cr | 32 ++++++++++++++++++++-- src/invidious/frontend/comments_youtube.cr | 8 ++++++ 3 files changed, 39 insertions(+), 2 deletions(-) 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