From fd6f03655eacdbd1dc3718017bb42793ee77fd47 Mon Sep 17 00:00:00 2001 From: syeopite Date: Fri, 3 Sep 2021 03:30:36 -0700 Subject: [PATCH 1/3] Fix typo causing links to be youtube.com/redirect --- src/invidious/comments.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index 3a4328a5..6dc27639 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -554,7 +554,7 @@ def content_to_comment_html(content) if url.host == "youtu.be" url = "/watch?v=#{url.request_target.lstrip('/')}" - elsif !url.host || {"m.youtube.com", "www.youtube.com"}.includes? url + elsif !url.host || {"m.youtube.com", "www.youtube.com"}.includes? url.host if url.path == "/redirect" url = HTTP::Params.parse(url.query.not_nil!)["q"] else From a28945273d99607b92eea1f05f57d7e1874fc20d Mon Sep 17 00:00:00 2001 From: syeopite Date: Fri, 3 Sep 2021 03:33:49 -0700 Subject: [PATCH 2/3] Propagate replacing yout.be links to /watch to RSS --- src/invidious/comments.cr | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index 6dc27639..5f607524 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -481,11 +481,15 @@ def replace_links(html) url = URI.parse(anchor["href"]) if {"www.youtube.com", "m.youtube.com", "youtu.be"}.includes?(url.host) - if url.path == "/redirect" - params = HTTP::Params.parse(url.query.not_nil!) - anchor["href"] = params["q"]? + if url.host == "youtu.be" + url = "/watch?v=#{url.request_target.lstrip('/')}" else - anchor["href"] = url.request_target + if url.path == "/redirect" + params = HTTP::Params.parse(url.query.not_nil!) + anchor["href"] = params["q"]? + else + anchor["href"] = url.request_target + end end elsif url.to_s == "#" begin From 387bddb51bfdea6a0679d1bd7bcccd2079105aae Mon Sep 17 00:00:00 2001 From: syeopite Date: Fri, 3 Sep 2021 12:28:34 -0700 Subject: [PATCH 3/3] Improve detection and handling of yt redirect links --- src/invidious/comments.cr | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index 5f607524..57fba565 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -480,9 +480,9 @@ def replace_links(html) html.xpath_nodes(%q(//a)).each do |anchor| url = URI.parse(anchor["href"]) - if {"www.youtube.com", "m.youtube.com", "youtu.be"}.includes?(url.host) - if url.host == "youtu.be" - url = "/watch?v=#{url.request_target.lstrip('/')}" + if url.host.nil? || url.host.not_nil!.ends_with?("youtube.com") || url.host.not_nil!.ends_with?("youtu.be") + if url.host.try &.ends_with? "youtu.be" + url = "/watch?v=#{url.path.lstrip('/')}#{url.query_params}" else if url.path == "/redirect" params = HTTP::Params.parse(url.query.not_nil!) @@ -558,7 +558,7 @@ def content_to_comment_html(content) if url.host == "youtu.be" url = "/watch?v=#{url.request_target.lstrip('/')}" - elsif !url.host || {"m.youtube.com", "www.youtube.com"}.includes? url.host + elsif url.host.nil? || url.host.not_nil!.ends_with?("youtube.com") if url.path == "/redirect" url = HTTP::Params.parse(url.query.not_nil!)["q"] else