mirror of
https://github.com/iv-org/invidious.git
synced 2024-06-07 19:40:52 +00:00
Fix link redirect for YouTube comments
This commit is contained in:
parent
133b72f9cf
commit
1c8bd671d8
@ -1917,8 +1917,12 @@ get "/api/v1/comments/:id" do |env|
|
|||||||
if url
|
if url
|
||||||
url = URI.parse(url)
|
url = URI.parse(url)
|
||||||
|
|
||||||
|
if {"m.youtube.com", "www.youtube.com", "youtu.be"}.includes? url.host
|
||||||
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
|
||||||
|
url = url.full_path
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
url = run["navigationEndpoint"]["commandMetadata"]?.try &.["webCommandMetadata"]["url"].as_s
|
url = run["navigationEndpoint"]["commandMetadata"]?.try &.["webCommandMetadata"]["url"].as_s
|
||||||
|
@ -196,15 +196,13 @@ 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"].includes?(url.host)
|
if {"www.youtube.com", "m.youtube.com", "youtu.be"}.includes?(url.host)
|
||||||
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.full_path
|
anchor["href"] = url.full_path
|
||||||
end
|
end
|
||||||
elsif url.host == "youtu.be"
|
|
||||||
anchor["href"] = "/watch?v=#{url.path.try &.lchop("/")}&#{url.query}"
|
|
||||||
elsif url.to_s == "#"
|
elsif url.to_s == "#"
|
||||||
begin
|
begin
|
||||||
length_seconds = decode_length_seconds(anchor.content)
|
length_seconds = decode_length_seconds(anchor.content)
|
||||||
|
Loading…
Reference in New Issue
Block a user