From 19805b91d90cc6e8648a213d0b46636392484f38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9ry=20Mathieu=20=28Mathius=29?= Date: Sat, 26 Feb 2022 17:53:39 +0100 Subject: [PATCH] Patch links related to youtube.com Related to followings comments : - https://github.com/iv-org/invidious/pull/2936#discussion_r815253405 --- src/invidious/comments.cr | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index ae8f052a0..1fd3dcfd4 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -573,26 +573,24 @@ def content_to_comment_html(content) if run["navigationEndpoint"]? if url = run["navigationEndpoint"]["urlEndpoint"]?.try &.["url"].as_s - base_url = URI.parse(url) url = URI.parse(url) + displayed_url = url if url.host == "youtu.be" - url = "youtube.com/watch?v=#{url.request_target.lstrip('/')}" + url = "/watch?v=#{url.request_target.lstrip('/')}" + displayed_url = "youtube.com#{url}" elsif url.host.nil? || url.host.not_nil!.ends_with?("youtube.com") if url.path == "/redirect" # Sometimes, links can be corrupted (why?) so make sure to fallback # nicely. See https://github.com/iv-org/invidious/issues/2682 url = HTTP::Params.parse(url.query.not_nil!)["q"]? || "" + displayed_url = url else url = url.request_target + displayed_url = "youtube.com#{url}" end end - if base_url.host.not_nil!.ends_with?("youtube.com") && base_url.path != "/redirect" - displayed_url = "youtube.com#{base_url.request_target}" - else - displayed_url = url - end text = %(#{reduce_uri(displayed_url)}) elsif watch_endpoint = run["navigationEndpoint"]["watchEndpoint"]? length_seconds = watch_endpoint["startTimeSeconds"]?