Merge pull request #2380 from syeopite/fix-invidious-showing-yt-redirect-links

Fix invidious showing yt redirect links
This commit is contained in:
TheFrenchGhosty 2021-09-06 11:15:08 +02:00 committed by GitHub
commit 8d5a867271
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -495,13 +495,17 @@ def replace_links(html)
html.xpath_nodes(%q(//a)).each do |anchor| html.xpath_nodes(%q(//a)).each do |anchor|
url = URI.parse(anchor["href"]) url = URI.parse(anchor["href"])
if {"www.youtube.com", "m.youtube.com", "youtu.be"}.includes?(url.host) 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" if url.path == "/redirect"
params = HTTP::Params.parse(url.query.not_nil!) params = HTTP::Params.parse(url.query.not_nil!)
anchor["href"] = params["q"]? anchor["href"] = params["q"]?
else else
anchor["href"] = url.request_target anchor["href"] = url.request_target
end end
end
elsif url.to_s == "#" elsif url.to_s == "#"
begin begin
length_seconds = decode_length_seconds(anchor.content) length_seconds = decode_length_seconds(anchor.content)
@ -569,7 +573,7 @@ def content_to_comment_html(content)
if url.host == "youtu.be" if url.host == "youtu.be"
url = "/watch?v=#{url.request_target.lstrip('/')}" 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" if url.path == "/redirect"
url = HTTP::Params.parse(url.query.not_nil!)["q"] url = HTTP::Params.parse(url.query.not_nil!)["q"]
else else