Skip to content

Commit 420c458

Browse files
committed
Update links related to youtube.com
Following comment at : - #2936 (comment)
1 parent 0f1bb3f commit 420c458

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/invidious/comments.cr

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,11 @@ def content_to_comment_html(content)
573573

574574
if run["navigationEndpoint"]?
575575
if url = run["navigationEndpoint"]["urlEndpoint"]?.try &.["url"].as_s
576+
base_url = URI.parse(url)
576577
url = URI.parse(url)
577578

578579
if url.host == "youtu.be"
579-
url = "/watch?v=#{url.request_target.lstrip('/')}"
580+
url = "youtube.com/watch?v=#{url.request_target.lstrip('/')}"
580581
elsif url.host.nil? || url.host.not_nil!.ends_with?("youtube.com")
581582
if url.path == "/redirect"
582583
# Sometimes, links can be corrupted (why?) so make sure to fallback
@@ -587,15 +588,20 @@ def content_to_comment_html(content)
587588
end
588589
end
589590

590-
text = %(<a href="#{url}">#{reduce_uri(url)}</a>)
591+
if base_url.host.not_nil!.ends_with?("youtube.com") && base_url.path != "/redirect"
592+
displayed_url = "youtube.com#{base_url.request_target}"
593+
else
594+
displayed_url = url
595+
end
596+
text = %(<a href="#{url}">#{reduce_uri(displayed_url)}</a>)
591597
elsif watch_endpoint = run["navigationEndpoint"]["watchEndpoint"]?
592598
length_seconds = watch_endpoint["startTimeSeconds"]?
593599
video_id = watch_endpoint["videoId"].as_s
594600

595601
if length_seconds && length_seconds.as_i > 0
596602
text = %(<a href="javascript:void(0)" data-onclick="jump_to_time" data-jump-time="#{length_seconds}">#{text}</a>)
597603
else
598-
text = %(<a href="/watch?v=#{video_id}">#{reduce_uri("/watch?v=#{video_id}")}</a>)
604+
text = %(<a href="/watch?v=#{video_id}">#{reduce_uri("youtube.com/watch?v=#{video_id}")}</a>)
599605
end
600606
elsif url = run.dig?("navigationEndpoint", "commandMetadata", "webCommandMetadata", "url").try &.as_s
601607
text = %(<a href="#{url}">#{reduce_uri(url)}</a>)

0 commit comments

Comments
 (0)