summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com>2023-02-15 00:20:45 -0500
committerChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com>2023-02-15 00:21:29 -0500
commitd03a62641f20a8dfd15fc9fe50373a5e75ee3d6e (patch)
tree7b8a452d331ab4c12cb2191c6e5f26c55e1d2d12 /src
parent7993784701686c057b85c57704537135e6326de9 (diff)
downloadinvidious-d03a62641f20a8dfd15fc9fe50373a5e75ee3d6e.tar.gz
invidious-d03a62641f20a8dfd15fc9fe50373a5e75ee3d6e.tar.bz2
invidious-d03a62641f20a8dfd15fc9fe50373a5e75ee3d6e.zip
Add support for custom emojis in comments
Diffstat (limited to 'src')
-rw-r--r--src/invidious/comments.cr14
1 files changed, 13 insertions, 1 deletions
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 = "<b>#{text}</b>" if run["bold"]?
text = "<s>#{text}</s>" if run["strikethrough"]?
text = "<i>#{text}</i>" 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 = "<img alt=\"#{emojiAlt}\" src=\"#{emojiUrl}\" width=\"#{emojiWidth}\" height=\"#{emojiHeight}\" style=\"margin-right:2px;margin-left:2px;\" />"
+ end
text
end