diff --git a/src/invidious/frontend/comments_youtube.cr b/src/invidious/frontend/comments_youtube.cr index 89d3caef..37aca49e 100644 --- a/src/invidious/frontend/comments_youtube.cr +++ b/src/invidious/frontend/comments_youtube.cr @@ -1,6 +1,222 @@ 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 + root.each do |child| + if child["replies"]? + replies_count_text = I18n.translate_count(locale, + "comments_view_x_replies", + child["replies"]["replyCount"].as_i64 || 0, + I18n::NumberFormatting::Separator + ) + + replies_html = <<-END_HTML +
+
+
+

+ #{replies_count_text} +

+
+
+ END_HTML + elsif comments["authorId"]? && !comments["singlePost"]? + # for posts we should display a link to the post + replies_count_text = I18n.translate_count(locale, + "comments_view_x_replies", + child["replyCount"].as_i64 || 0, + I18n::NumberFormatting::Separator + ) + + replies_html = <<-END_HTML +
+
+
+

+ #{replies_count_text} +

+
+
+ END_HTML + end + + if !thin_mode + author_thumbnail = "/ggpht#{URI.parse(child["authorThumbnails"][-1]["url"].as_s).request_target}" + else + author_thumbnail = "" + end + + author_name = HTML.escape(child["author"].as_s) + sponsor_icon = "" + if child["verified"]?.try &.as_bool && child["authorIsChannelOwner"]?.try &.as_bool + author_name += " " + elsif child["verified"]?.try &.as_bool + author_name += " " + end + + if child["isSponsor"]?.try &.as_bool + sponsor_icon = String.build do |str| + str << %() + end + end + html << <<-END_HTML +
+
+ +
+
+

+ + #{author_name} + + #{sponsor_icon} +

#{child["contentHtml"]}

+ END_HTML + + if child["attachment"]? + attachment = child["attachment"] + + case attachment["type"] + when "image" + attachment = attachment["imageThumbnails"][1] + + html << <<-END_HTML +
+
+ +
+
+ END_HTML + when "video" + if attachment["error"]? + html << <<-END_HTML +
+

#{attachment["error"]}

+
+ END_HTML + else + html << <<-END_HTML +
+ +
+ END_HTML + end + when "multiImage" + html << <<-END_HTML + + END_HTML + else nil # Ignore + end + end + + html << <<-END_HTML +

+ #{I18n.translate(locale, "`x` ago", recode_date(Time.unix(child["published"].as_i64), locale))} #{child["isEdited"] == true ? I18n.translate(locale, "(edited)") : ""} + | + END_HTML + + if comments["videoId"]? + html << <<-END_HTML + [YT] + | + END_HTML + elsif comments["authorId"]? + html << <<-END_HTML + [YT] + | + END_HTML + end + + html << <<-END_HTML + #{number_with_separator(child["likeCount"])} + END_HTML + + if child["creatorHeart"]? + if !thin_mode + creator_thumbnail = "/ggpht#{URI.parse(child["creatorHeart"]["creatorThumbnail"].as_s).request_target}" + else + creator_thumbnail = "" + end + + html << <<-END_HTML +   + + + + + + + + + END_HTML + end + + html << <<-END_HTML +

+ #{replies_html} +
+
+ END_HTML + end + + if comments["continuation"]? + html << <<-END_HTML +
+
+

+ #{I18n.translate(locale, "Load more")} +

+
+
+ END_HTML + end + end + end +end +module Invidious::Frontend::Comments + extend self + def template_youtube(comments, locale, thin_mode, is_replies = false) String.build do |html| root = comments["comments"].as_a