Invidious is an alternative front-end to YouTube
Fix link redirect for YouTube comments
Omar Roth1c8bd671d8a8
diff --git a/src/invidious.cr b/src/invidious.crindex 78cbd454..5220b387 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -1917,8 +1917,12 @@ get "/api/v1/comments/:id" do |env|if urlurl = URI.parse(url)+ if {"m.youtube.com", "www.youtube.com", "youtu.be"}.includes? url.hostif url.path == "/redirect"url = HTTP::Params.parse(url.query.not_nil!)["q"]+ else+ url = url.full_path+ endendelseurl = run["navigationEndpoint"]["commandMetadata"]?.try &.["webCommandMetadata"]["url"].as_sdiff --git a/src/invidious/comments.cr b/src/invidious/comments.crindex c135497e..70746499 100644--- a/src/invidious/comments.cr+++ b/src/invidious/comments.cr@@ -196,15 +196,13 @@ def replace_links(html)html.xpath_nodes(%q(//a)).each do |anchor|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"params = HTTP::Params.parse(url.query.not_nil!)anchor["href"] = params["q"]?elseanchor["href"] = url.full_pathend- elsif url.host == "youtu.be"- anchor["href"] = "/watch?v=#{url.path.try &.lchop("/")}&#{url.query}"elsif url.to_s == "#"beginlength_seconds = decode_length_seconds(anchor.content)