Add additional channel endpoints to brand_redirect

(cherry picked from commit 8fc6f3add637dabb09b2034f4d82fc3d039ba15c)
This commit is contained in:
syeopite 2021-06-26 21:14:55 -07:00
parent 5f4fc06553
commit 36a4647fba
No known key found for this signature in database
GPG Key ID: 6FA616E5A5294A82

View File

@ -317,6 +317,9 @@ Invidious::Routing.get "/channel/:ucid/about", Invidious::Routes::Channels, :abo
["", "/videos", "/playlists", "/community", "/about"].each do |path|
Invidious::Routing.get "/c/:user#{path}", Invidious::Routes::Channels, :brand_redirect
Invidious::Routing.get "/user/:user#{path}", Invidious::Routes::Channels, :brand_redirect
Invidious::Routing.get "/attribution_link#{path}", Invidious::Routes::Channels, :brand_redirect
Invidious::Routing.get "/profile/:user#{path}", Invidious::Routes::Channels, :brand_redirect
end
Invidious::Routing.get "/watch", Invidious::Routes::Watch, :handle
@ -1628,57 +1631,6 @@ end
end
end
# YouTube appears to let users set a "brand" URL that
# is different from their username, so we convert that here
get "/c/:user" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
user = env.params.url["user"]
response = YT_POOL.client &.get("/c/#{user}")
html = XML.parse_html(response.body)
ucid = html.xpath_node(%q(//link[@rel="canonical"])).try &.["href"].split("/")[-1]
next env.redirect "/" if !ucid
env.redirect "/channel/#{ucid}"
end
# Legacy endpoint for /user/:username
get "/profile" do |env|
user = env.params.query["user"]?
if !user
env.redirect "/"
else
env.redirect "/user/#{user}"
end
end
get "/attribution_link" do |env|
if query = env.params.query["u"]?
url = URI.parse(query).request_target
else
url = "/"
end
env.redirect url
end
get "/user/:user" do |env|
user = env.params.url["user"]
env.redirect "/channel/#{user}"
end
get "/user/:user/videos" do |env|
user = env.params.url["user"]
env.redirect "/channel/#{user}/videos"
end
get "/user/:user/about" do |env|
user = env.params.url["user"]
env.redirect "/channel/#{user}"
end
# API Endpoints
get "/api/v1/stats" do |env|