summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-09-19 15:25:49 -0500
committerOmar Roth <omarroth@hotmail.com>2018-09-19 15:25:49 -0500
commit2c6f8022e6a8c9053231d6b2765cb6fdb4904791 (patch)
tree64a8cc0bc6833fc49d7060bd529f1d603faa1db4
parentfe5286a210425a41e3ec36533fdc06681ded3799 (diff)
downloadinvidious-2c6f8022e6a8c9053231d6b2765cb6fdb4904791.tar.gz
invidious-2c6f8022e6a8c9053231d6b2765cb6fdb4904791.tar.bz2
invidious-2c6f8022e6a8c9053231d6b2765cb6fdb4904791.zip
Fix comments where link has no host
-rw-r--r--src/invidious.cr38
-rw-r--r--src/invidious/comments.cr43
2 files changed, 44 insertions, 37 deletions
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 = "<br>"
- end
-
- if run["bold"]?
- text = "<b>#{text}</b>"
- end
-
- if run["italics"]?
- text = "<i>#{text}</i>"
- 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 = %(<a href="#{url}">#{text}</a>)
- 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 = "<br>"
+ end
+
+ if run["bold"]?
+ text = "<b>#{text}</b>"
+ end
+
+ if run["italics"]?
+ text = "<i>#{text}</i>"
+ 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 = %(<a href="#{url}">#{text}</a>)
+ end
+
+ text
+ end.join.rchop('\ufeff')
+
+ return comment_html
+end