`;
+
+ document.getElementById("try-reddit-comments-link").onclick = swap_comments;
+ } else {
+ comments.innerHTML = fallback;
+ }
+
+ };
+
if (video_data.params.comments[1] === 'youtube')
onNon200 = function (xhr) {};
diff --git a/assets/js/watch.js b/assets/js/watch.js
index ee9c29e8..a2d8d26e 100644
--- a/assets/js/watch.js
+++ b/assets/js/watch.js
@@ -182,6 +182,10 @@ addEventListener('load', function (e) {
if (video_data.plid)
get_playlist(video_data.plid);
+ if (!video_data.comments_enabled && video_data.params.comments.includes("youtube")) {
+ return;
+ }
+
if (video_data.params.comments[0] === 'youtube') {
get_youtube_comments();
} else if (video_data.params.comments[0] === 'reddit') {
@@ -190,8 +194,7 @@ addEventListener('load', function (e) {
get_youtube_comments();
} else if (video_data.params.comments[1] === 'reddit') {
get_reddit_comments();
- } else {
- var comments = document.getElementById('comments');
- comments.innerHTML = '';
}
});
+
+document.getElementById("try-reddit-comments-link").onclick = swap_comments;
diff --git a/locales/en-US.json b/locales/en-US.json
index d05c0d16..8032cf98 100644
--- a/locales/en-US.json
+++ b/locales/en-US.json
@@ -222,6 +222,10 @@
"View Reddit comments": "View Reddit comments",
"Hide replies": "Hide replies",
"Show replies": "Show replies",
+ "comments_youtube_disabled_text": "Youtube comments are disabled on this video",
+ "comments_youtube_disabled_try_reddit": "Try reddit comments?",
+ "comments_invidious_disabled_text": "Comments are hidden as per user preferences",
+ "comments_youtube_disabled_try_reddit_no_js": "Hi! Looks like you have JavaScript turned off. Although the uploader has disabled YouTube comments you can still click here to try and view Reddit comments, keep in mind they may take a bit longer to load.",
"Incorrect password": "Incorrect password",
"Wrong answer": "Wrong answer",
"Erroneous CAPTCHA": "Erroneous CAPTCHA",
diff --git a/src/invidious/routes/watch.cr b/src/invidious/routes/watch.cr
index 7a68a145..3c66f1bc 100644
--- a/src/invidious/routes/watch.cr
+++ b/src/invidious/routes/watch.cr
@@ -79,7 +79,8 @@ module Invidious::Routes::Watch
if nojs
if preferences
- source = preferences.comments[0]
+ source = video.comments? ? preferences.comments[0] : "reddit"
+
if source.empty?
source = preferences.comments[1]
end
diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr
index 99713d18..ba947b2b 100644
--- a/src/invidious/videos.cr
+++ b/src/invidious/videos.cr
@@ -193,6 +193,11 @@ struct Video
}
end
+ # Returns true if comments are enabled on the video
+ def comments?
+ return info["commentsEnabled"].as_bool
+ end
+
# Macros defining getters/setters for various types of data
private macro getset_string(name)
diff --git a/src/invidious/videos/parser.cr b/src/invidious/videos/parser.cr
index 914c5963..8367fcd7 100644
--- a/src/invidious/videos/parser.cr
+++ b/src/invidious/videos/parser.cr
@@ -295,6 +295,18 @@ module Invidious::Videos::Parser
"likeButton", "toggleButtonRenderer"
)
+ # Comments enabled?
+ comments_enabled = false
+
+ # When comments are enabled there should be a comments-section section in the primary results
+ if primary_results
+ section = primary_results.as_a.find(&.dig?("itemSectionRenderer", "targetId").== "comments-section")
+
+ if section
+ comments_enabled = true
+ end
+ end
+
if likes_button
likes_txt = likes_button.dig?("accessibilityText")
# Note: The like count from `toggledText` is off by one, as it would
@@ -421,6 +433,7 @@ module Invidious::Videos::Parser
"isFamilyFriendly" => JSON::Any.new(family_friendly || false),
"isListed" => JSON::Any.new(is_listed || false),
"isUpcoming" => JSON::Any.new(is_upcoming || false),
+ "commentsEnabled" => JSON::Any.new(comments_enabled),
"keywords" => JSON::Any.new(keywords.map { |v| JSON::Any.new(v) }),
"isPostLiveDvr" => JSON::Any.new(post_live_dvr),
# Related videos
diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr
index 796c0c91..ec8c5a98 100644
--- a/src/invidious/views/watch.ecr
+++ b/src/invidious/views/watch.ecr
@@ -42,6 +42,12 @@ we're going to need to do it here in order to allow for translations.
content: "<%= I18n.translate(locale, "Show less") %>"
}
+
+<%
+ # Disable the try reddit link if javascript is disabled
+%>
+
+
<% end %>
${video_data.comments_youtube_disabled_text}
+ ++