From d03a62641f20a8dfd15fc9fe50373a5e75ee3d6e Mon Sep 17 00:00:00 2001 From: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Wed, 15 Feb 2023 00:20:45 -0500 Subject: [PATCH 1/6] Add support for custom emojis in comments --- src/invidious/comments.cr | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index 357a461c..5749248e 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -182,7 +182,11 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b json.field "contentHtml", content_html json.field "isPinned", (node_comment["pinnedCommentBadge"]? != nil) - + json.field "isMember", (node_comment["sponsorCommentBadge"]? != nil) + if node_comment["sponsorCommentBadge"]? + # Member icon thumbnails always have one object and there's only ever the url property in it + json.field "memberIconUrl", node_comment["sponsorCommentBadge"]["sponsorCommentBadgeRenderer"]["customBadge"]["thumbnails"][0]["url"].to_s + end json.field "published", published.to_unix json.field "publishedText", translate(locale, "`x` ago", recode_date(published, locale)) @@ -674,6 +678,14 @@ def content_to_comment_html(content, video_id : String? = "") text = "#{text}" if run["bold"]? text = "#{text}" if run["strikethrough"]? text = "#{text}" if run["italics"]? + if emojiImage = run.dig?("emoji", "image") + emojiAlt = emojiImage.dig?("accessibility", "accessibilityData", "label").try &.as_s || text + emojiThumb = emojiImage["thumbnails"][0] + emojiUrl = "/ggpht#{URI.parse(emojiThumb["url"].as_s).request_target}" + emojiWidth = emojiThumb["width"] + emojiHeight = emojiThumb["height"] + text = "\"#{emojiAlt}\"" + end text end From 76ad4e802603f82fe45d522a9c268e972d428a75 Mon Sep 17 00:00:00 2001 From: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Thu, 16 Feb 2023 14:12:56 -0500 Subject: [PATCH 2/6] show member icon, hide deleted emojis, fix non-custom emojis --- locales/en-US.json | 1 + src/invidious/comments.cr | 29 ++++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/locales/en-US.json b/locales/en-US.json index a5c16fd7..5bbf6db6 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -405,6 +405,7 @@ "YouTube comment permalink": "YouTube comment permalink", "permalink": "permalink", "`x` marked it with a ❤": "`x` marked it with a ❤", + "Member": "Member", "Audio mode": "Audio mode", "Video mode": "Video mode", "Playlists": "Playlists", diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index 5749248e..f1942ceb 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -328,11 +328,21 @@ def template_youtube_comments(comments, locale, thin_mode, is_replies = false) end author_name = HTML.escape(child["author"].as_s) + member_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["isMember"]?.try &.as_bool + member_icon = "\"\"" + end html << <<-END_HTML
@@ -343,6 +353,7 @@ def template_youtube_comments(comments, locale, thin_mode, is_replies = false) #{author_name} + #{member_icon}

#{child["contentHtml"]}

END_HTML @@ -678,13 +689,17 @@ def content_to_comment_html(content, video_id : String? = "") text = "#{text}" if run["bold"]? text = "#{text}" if run["strikethrough"]? text = "#{text}" if run["italics"]? - if emojiImage = run.dig?("emoji", "image") - emojiAlt = emojiImage.dig?("accessibility", "accessibilityData", "label").try &.as_s || text - emojiThumb = emojiImage["thumbnails"][0] - emojiUrl = "/ggpht#{URI.parse(emojiThumb["url"].as_s).request_target}" - emojiWidth = emojiThumb["width"] - emojiHeight = emojiThumb["height"] - text = "\"#{emojiAlt}\"" + if run["emoji"]? + if run["emoji"]["isCustomEmoji"]?.try &.as_bool + if emojiImage = run.dig?("emoji", "image") + emojiAlt = emojiImage.dig?("accessibility", "accessibilityData", "label").try &.as_s || text + emojiThumb = emojiImage["thumbnails"][0] + text = "\"#{emojiAlt}\"" + else + # Hide deleted channel emoji + text = "" + end + end end text From bc5d81fe60b324459ac428f4269316bd4cfdc3a1 Mon Sep 17 00:00:00 2001 From: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Sun, 19 Feb 2023 12:46:46 -0500 Subject: [PATCH 3/6] use string builder to create images change member to sponsor --- locales/en-US.json | 2 +- src/invidious/comments.cr | 36 ++++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/locales/en-US.json b/locales/en-US.json index 5bbf6db6..bd2b9d44 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -405,7 +405,7 @@ "YouTube comment permalink": "YouTube comment permalink", "permalink": "permalink", "`x` marked it with a ❤": "`x` marked it with a ❤", - "Member": "Member", + "Channel Sponsor": "Channel Sponsor", "Audio mode": "Audio mode", "Video mode": "Video mode", "Playlists": "Playlists", diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index f1942ceb..b866b6ef 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -182,10 +182,10 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b json.field "contentHtml", content_html json.field "isPinned", (node_comment["pinnedCommentBadge"]? != nil) - json.field "isMember", (node_comment["sponsorCommentBadge"]? != nil) + json.field "isSponsor", (node_comment["sponsorCommentBadge"]? != nil) if node_comment["sponsorCommentBadge"]? - # Member icon thumbnails always have one object and there's only ever the url property in it - json.field "memberIconUrl", node_comment["sponsorCommentBadge"]["sponsorCommentBadgeRenderer"]["customBadge"]["thumbnails"][0]["url"].to_s + # Sponsor icon thumbnails always have one object and there's only ever the url property in it + json.field "sponsorIconUrl", node_comment.dig("sponsorCommentBadge", "sponsorCommentBadgeRenderer", "customBadge", "thumbnails", 0, "url").to_s end json.field "published", published.to_unix json.field "publishedText", translate(locale, "`x` ago", recode_date(published, locale)) @@ -328,20 +328,19 @@ def template_youtube_comments(comments, locale, thin_mode, is_replies = false) end author_name = HTML.escape(child["author"].as_s) - member_icon = "" + 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["isMember"]?.try &.as_bool - member_icon = "\"\"" + if child["isSponsor"].as_bool + sponsor_icon = String.build do |str| + str << %() + end end html << <<-END_HTML
@@ -353,7 +352,7 @@ def template_youtube_comments(comments, locale, thin_mode, is_replies = false) #{author_name} - #{member_icon} + #{sponsor_icon}

#{child["contentHtml"]}

END_HTML @@ -689,12 +688,21 @@ def content_to_comment_html(content, video_id : String? = "") text = "#{text}" if run["bold"]? text = "#{text}" if run["strikethrough"]? text = "#{text}" if run["italics"]? + + # check for custom emojis if run["emoji"]? if run["emoji"]["isCustomEmoji"]?.try &.as_bool if emojiImage = run.dig?("emoji", "image") emojiAlt = emojiImage.dig?("accessibility", "accessibilityData", "label").try &.as_s || text emojiThumb = emojiImage["thumbnails"][0] - text = "\"#{emojiAlt}\"" + text = String.build do |str| + str << %() << emojiAlt << ') + end else # Hide deleted channel emoji text = "" From b5eb6016bbc455921ce3d8ec24589d706f8a5fb1 Mon Sep 17 00:00:00 2001 From: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Sun, 19 Feb 2023 14:51:39 -0500 Subject: [PATCH 4/6] add spaces at end of attribute --- src/invidious/comments.cr | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index b866b6ef..6c323bc1 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -336,10 +336,10 @@ def template_youtube_comments(comments, locale, thin_mode, is_replies = false) end if child["isSponsor"].as_bool sponsor_icon = String.build do |str| - str << %() + str << %() end end html << <<-END_HTML @@ -696,12 +696,12 @@ def content_to_comment_html(content, video_id : String? = "") emojiAlt = emojiImage.dig?("accessibility", "accessibilityData", "label").try &.as_s || text emojiThumb = emojiImage["thumbnails"][0] text = String.build do |str| - str << %() << emojiAlt << ') + str << %() << emojiAlt << ) end else # Hide deleted channel emoji From 60b7c8015c9ae77664d0b0680a81cfcc979d5a03 Mon Sep 17 00:00:00 2001 From: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Thu, 2 Mar 2023 07:29:44 -0500 Subject: [PATCH 5/6] add channel emoji css class --- assets/css/default.css | 4 ++++ src/invidious/comments.cr | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/assets/css/default.css b/assets/css/default.css index 9788e9f7..5ec79a43 100644 --- a/assets/css/default.css +++ b/assets/css/default.css @@ -565,3 +565,7 @@ p, /* Wider settings name to less word wrap */ .pure-form-aligned .pure-control-group label { width: 19em; } + +.channel-emoji { + margin: 0 2px; +} diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index 6c323bc1..56622dec 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -701,7 +701,7 @@ def content_to_comment_html(content, video_id : String? = "") str << %(title=") << emojiAlt << "\" " str << %(width=") << emojiThumb["width"] << "\" " str << %(height=") << emojiThumb["height"] << "\" " - str << %(style="margin-right:2px;margin-left:2px;"/>) + str << %(class="channel-emoji"/>) end else # Hide deleted channel emoji From a781cf37347e97c469eb098e95c9a80482aac1b9 Mon Sep 17 00:00:00 2001 From: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Tue, 7 Mar 2023 15:59:51 -0500 Subject: [PATCH 6/6] readd try as bool for isSponsor key --- src/invidious/comments.cr | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index 56622dec..b15d63d4 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -334,7 +334,8 @@ def template_youtube_comments(comments, locale, thin_mode, is_replies = false) elsif child["verified"]?.try &.as_bool author_name += " " end - if child["isSponsor"].as_bool + + if child["isSponsor"]?.try &.as_bool sponsor_icon = String.build do |str| str << %(