diff --git a/src/invidious.cr b/src/invidious.cr
index 1d0a8238..163e1d24 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -1964,43 +1964,7 @@ get "/api/v1/comments/:id" do |env|
content_html = HTML.escape(content_html)
end
- content_html ||= node_comment["contentText"]["runs"].as_a.map do |run|
- text = HTML.escape(run["text"].as_s)
-
- if run["text"] == "\n"
- text = "
"
- end
-
- if run["bold"]?
- text = "#{text}"
- end
-
- if run["italics"]?
- text = "#{text}"
- end
-
- if run["navigationEndpoint"]?
- url = run["navigationEndpoint"]["urlEndpoint"]?.try &.["url"].as_s
- if url
- url = URI.parse(url)
-
- if {"m.youtube.com", "www.youtube.com", "youtu.be"}.includes? url.host
- if url.path == "/redirect"
- url = HTTP::Params.parse(url.query.not_nil!)["q"]
- else
- url = url.full_path
- end
- end
- else
- url = run["navigationEndpoint"]["commandMetadata"]?.try &.["webCommandMetadata"]["url"].as_s
- end
-
- text = %(#{text})
- end
-
- text
- end.join.rchop('\ufeff')
-
+ content_html ||= content_to_comment_html(node_comment["contentText"]["runs"].as_a)
content_html, content = html_to_content(content_html)
author = node_comment["authorText"]?.try &.["simpleText"]
diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr
index 20716dcc..263fab2e 100644
--- a/src/invidious/comments.cr
+++ b/src/invidious/comments.cr
@@ -242,3 +242,46 @@ def fill_links(html, scheme, host)
return html
end
+
+def content_to_comment_html(content)
+ comment_html = content.map do |run|
+ text = HTML.escape(run["text"].as_s)
+
+ if run["text"] == "\n"
+ text = "
"
+ end
+
+ if run["bold"]?
+ text = "#{text}"
+ end
+
+ if run["italics"]?
+ text = "#{text}"
+ end
+
+ if run["navigationEndpoint"]?
+ url = run["navigationEndpoint"]["urlEndpoint"]?.try &.["url"].as_s
+ if url
+ url = URI.parse(url)
+
+ puts url.path
+ puts url.host
+ if !url.host || {"m.youtube.com", "www.youtube.com", "youtu.be"}.includes? url.host
+ if url.path == "/redirect"
+ url = HTTP::Params.parse(url.query.not_nil!)["q"]
+ else
+ url = url.full_path
+ end
+ end
+ else
+ url = run["navigationEndpoint"]["commandMetadata"]?.try &.["webCommandMetadata"]["url"].as_s
+ end
+
+ text = %(#{text})
+ end
+
+ text
+ end.join.rchop('\ufeff')
+
+ return comment_html
+end