Patch links related to youtube.com

Related to followings comments :
- https://github.com/iv-org/invidious/pull/2936#discussion_r815253405
pull/2936/head
Féry Mathieu (Mathius) 3 years ago
parent 420c458b6a
commit 19805b91d9
No known key found for this signature in database
GPG Key ID: F9CCC80C18A59037

@ -573,26 +573,24 @@ def content_to_comment_html(content)
if run["navigationEndpoint"]? if run["navigationEndpoint"]?
if url = run["navigationEndpoint"]["urlEndpoint"]?.try &.["url"].as_s if url = run["navigationEndpoint"]["urlEndpoint"]?.try &.["url"].as_s
base_url = URI.parse(url)
url = URI.parse(url) url = URI.parse(url)
displayed_url = url
if url.host == "youtu.be" 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") elsif url.host.nil? || url.host.not_nil!.ends_with?("youtube.com")
if url.path == "/redirect" if url.path == "/redirect"
# Sometimes, links can be corrupted (why?) so make sure to fallback # Sometimes, links can be corrupted (why?) so make sure to fallback
# nicely. See https://github.com/iv-org/invidious/issues/2682 # nicely. See https://github.com/iv-org/invidious/issues/2682
url = HTTP::Params.parse(url.query.not_nil!)["q"]? || "" url = HTTP::Params.parse(url.query.not_nil!)["q"]? || ""
displayed_url = url
else else
url = url.request_target url = url.request_target
displayed_url = "youtube.com#{url}"
end end
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 = %(<a href="#{url}">#{reduce_uri(displayed_url)}</a>) text = %(<a href="#{url}">#{reduce_uri(displayed_url)}</a>)
elsif watch_endpoint = run["navigationEndpoint"]["watchEndpoint"]? elsif watch_endpoint = run["navigationEndpoint"]["watchEndpoint"]?
length_seconds = watch_endpoint["startTimeSeconds"]? length_seconds = watch_endpoint["startTimeSeconds"]?

Loading…
Cancel
Save