Show message for disabled YouTube comments

This commit is contained in:
Nickita Khylkouski 2026-05-11 01:02:18 -07:00
parent f914ce8040
commit 633f6e2592
3 changed files with 64 additions and 2 deletions

View File

@ -236,6 +236,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

@ -0,0 +1,57 @@
require "../../parsers_helper"
require "../../../src/invidious/helpers/helpers"
require "../../../src/invidious/helpers/i18next"
require "../../../src/invidious/helpers/i18n"
require "../../../src/invidious/yt_backend/youtube_api"
require "../../../src/invidious/frontend/comments_youtube"
require "../../../src/invidious/comments/youtube"
Spectator.describe Invidious::Comments do
describe ".parse_youtube" do
it "shows a message when comments are disabled" do
response = JSON.parse({
"onResponseReceivedEndpoints" => [
{
"reloadContinuationItemsCommand" => {
"slot" => "RELOAD_CONTINUATION_SLOT_HEADER",
"continuationItems" => [
{
"commentsHeaderRenderer" => {
"countText" => {"simpleText" => "0 Comments"},
},
},
],
},
},
{
"reloadContinuationItemsCommand" => {
"slot" => "RELOAD_CONTINUATION_SLOT_BODY",
},
},
],
}.to_json)
parsed = JSON.parse(Invidious::Comments.parse_youtube("video-id", response, "html", "en-US", false))
expect(parsed["contentHtml"].as_s).to contain("Comments are turned off.")
expect(parsed["commentCount"].as_i).to eq(0)
end
it "marks disabled comments in JSON responses" do
response = JSON.parse({
"onResponseReceivedEndpoints" => [
{
"reloadContinuationItemsCommand" => {
"slot" => "RELOAD_CONTINUATION_SLOT_BODY",
},
},
],
}.to_json)
parsed = JSON.parse(Invidious::Comments.parse_youtube("video-id", response, "json", "en-US", false))
expect(parsed["comments"].as_a).to be_empty
expect(parsed["commentsDisabled"].as_bool).to be_true
end
end
end

View File

@ -94,9 +94,13 @@ module Invidious::Comments
if !contents
if format == "json"
return {"comments" => [] of String}.to_json
return {
"comments" => [] of String,
"commentsDisabled" => true,
}.to_json
else
return {"contentHtml" => "", "commentCount" => 0}.to_json
message = HTML.escape(I18n.translate(locale, "Comments are turned off."))
return {"contentHtml" => "<p>#{message}</p>", "commentCount" => 0}.to_json
end
end