diff options
| author | TheFrenchGhosty <47571719+TheFrenchGhosty@users.noreply.github.com> | 2021-09-06 11:15:08 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-06 11:15:08 +0200 |
| commit | 8d5a86727134383138853a024bec172559f38a4f (patch) | |
| tree | 52c1ef71448405c46d3302523855f6bf8f9f5e6e | |
| parent | 6a1954f8f7e9ca26aec25a9d7cba7c5a48365422 (diff) | |
| parent | 387bddb51bfdea6a0679d1bd7bcccd2079105aae (diff) | |
| download | invidious-8d5a86727134383138853a024bec172559f38a4f.tar.gz invidious-8d5a86727134383138853a024bec172559f38a4f.tar.bz2 invidious-8d5a86727134383138853a024bec172559f38a4f.zip | |
Merge pull request #2380 from syeopite/fix-invidious-showing-yt-redirect-links
Fix invidious showing yt redirect links
| -rw-r--r-- | src/invidious/comments.cr | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index a5617796..a5506b03 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -495,12 +495,16 @@ 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.path == "/redirect" - params = HTTP::Params.parse(url.query.not_nil!) - anchor["href"] = params["q"]? + 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 - 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 @@ -569,7 +573,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.nil? || url.host.not_nil!.ends_with?("youtube.com") if url.path == "/redirect" url = HTTP::Params.parse(url.query.not_nil!)["q"] else |
