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
This commit is contained in:
Alex DevTech 2026-07-30 18:08:46 -07:00
parent b7697e97c3
commit feff91a225
3 changed files with 39 additions and 2 deletions

View File

@ -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",

View File

@ -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

View File

@ -1,6 +1,14 @@
module Invidious::Frontend::Comments
extend self
def template_youtube_disabled(locale)
<<-END_HTML
<div class="h-box">
<p>#{I18n.translate(locale, "Comments are turned off")}</p>
</div>
END_HTML
end
def template_youtube(comments, locale, thin_mode, is_replies = false)
String.build do |html|
root = comments["comments"].as_a