mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-27 01:01:59 +05:30
Update links related to youtube.com
Following comment at : - https://github.com/iv-org/invidious/pull/2936#discussion_r814435888
This commit is contained in:
parent
0f1bb3fb3b
commit
420c458b6a
@ -573,10 +573,11 @@ 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)
|
||||
|
||||
if url.host == "youtu.be"
|
||||
url = "/watch?v=#{url.request_target.lstrip('/')}"
|
||||
url = "youtube.com/watch?v=#{url.request_target.lstrip('/')}"
|
||||
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
|
||||
@ -587,7 +588,12 @@ def content_to_comment_html(content)
|
||||
end
|
||||
end
|
||||
|
||||
text = %(<a href="#{url}">#{reduce_uri(url)}</a>)
|
||||
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>)
|
||||
elsif watch_endpoint = run["navigationEndpoint"]["watchEndpoint"]?
|
||||
length_seconds = watch_endpoint["startTimeSeconds"]?
|
||||
video_id = watch_endpoint["videoId"].as_s
|
||||
@ -595,7 +601,7 @@ def content_to_comment_html(content)
|
||||
if length_seconds && length_seconds.as_i > 0
|
||||
text = %(<a href="javascript:void(0)" data-onclick="jump_to_time" data-jump-time="#{length_seconds}">#{text}</a>)
|
||||
else
|
||||
text = %(<a href="/watch?v=#{video_id}">#{reduce_uri("/watch?v=#{video_id}")}</a>)
|
||||
text = %(<a href="/watch?v=#{video_id}">#{reduce_uri("youtube.com/watch?v=#{video_id}")}</a>)
|
||||
end
|
||||
elsif url = run.dig?("navigationEndpoint", "commandMetadata", "webCommandMetadata", "url").try &.as_s
|
||||
text = %(<a href="#{url}">#{reduce_uri(url)}</a>)
|
||||
|
Loading…
Reference in New Issue
Block a user