Skip to content

Commit

Permalink
Parse links in the comments
Browse files Browse the repository at this point in the history
Co-Authored-By: Samantaz Fox <coding@samantaz.fr>
  • Loading branch information
ChunkyProgrammer and SamantazFox committed Apr 11, 2024
1 parent de22879 commit aaed01f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/invidious/comments/content.cr
Expand Up @@ -64,15 +64,15 @@ def content_to_comment_html(content, video_id : String? = "")
# 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]
if emoji_image = run.dig?("emoji", "image")
emoji_alt = emoji_image.dig?("accessibility", "accessibilityData", "label").try &.as_s || text
emoji_thumb = emoji_image["thumbnails"][0]
text = String.build do |str|
str << %(<img alt=") << emojiAlt << "\" "
str << %(src="/ggpht) << URI.parse(emojiThumb["url"].as_s).request_target << "\" "
str << %(title=") << emojiAlt << "\" "
str << %(width=") << emojiThumb["width"] << "\" "
str << %(height=") << emojiThumb["height"] << "\" "
str << %(<img alt=") << emoji_alt << "\" "
str << %(src="/ggpht) << URI.parse(emoji_thumb["url"].as_s).request_target << "\" "
str << %(title=") << emoji_alt << "\" "
str << %(width=") << emoji_thumb["width"] << "\" "
str << %(height=") << emoji_thumb["height"] << "\" "
str << %(class="channel-emoji" />)
end
else
Expand Down
2 changes: 1 addition & 1 deletion src/invidious/comments/youtube.cr
Expand Up @@ -144,7 +144,7 @@ module Invidious::Comments
toolbar_mutation = mutations.find { |i| i.dig?("entityKey") == toolbar_key }
if !comment_mutation.nil? && !toolbar_mutation.nil?
# todo parse styleRuns, commandRuns and attachmentRuns for comments
html_content = HTML.escape(comment_mutation.dig("payload", "commentEntityPayload", "properties", "content", "content").as_s)
html_content = parse_description(comment_mutation.dig("payload", "commentEntityPayload", "properties", "content"), id)
comment_author = comment_mutation.dig("payload", "commentEntityPayload", "author")
json.field "authorId", comment_author["channelId"].as_s
json.field "authorUrl", "/channel/#{comment_author["channelId"].as_s}"
Expand Down
14 changes: 13 additions & 1 deletion src/invidious/videos/description.cr
Expand Up @@ -7,7 +7,19 @@ private def copy_string(str : String::Builder, iter : Iterator, count : Int) : I
cp = iter.next
break if cp.is_a?(Iterator::Stop)

str << cp.chr
if cp == 0x26 # Ampersand (&)
str << "&amp;"
elsif cp == 0x27 # Single quote (')
str << "&#39;"
elsif cp == 0x22 # Double quote (")
str << "&quot;"
elsif cp == 0x3C # Less-than (<)
str << "&lt;"
elsif cp == 0x3E # Greater than (>)
str << "&gt;"
else
str << cp.chr
end

# A codepoint from the SMP counts twice
copied += 1 if cp > 0xFFFF
Expand Down

0 comments on commit aaed01f

Please sign in to comment.