mirror of
https://github.com/iv-org/invidious
synced 2024-11-10 21:23:34 +01:00
Update brand_redirect to use youtubei resolve_url
This commit is contained in:
parent
59169c2aa0
commit
53335fe7cf
@ -166,25 +166,23 @@ class Invidious::Routes::Channels < Invidious::Routes::BaseRoute
|
|||||||
templated "channel/about", buffer_footer: true
|
templated "channel/about", buffer_footer: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Redirects brand url channels to a normal /channel/:ucid route
|
||||||
def brand_redirect(env)
|
def brand_redirect(env)
|
||||||
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
||||||
|
|
||||||
user = env.params.url["user"]
|
begin
|
||||||
|
resolved_url = request_youtube_api_resolve_url("https://youtube.com#{env.request.path}")
|
||||||
response = YT_POOL.client &.get("/c/#{user}")
|
rescue ex : InfoException
|
||||||
html = XML.parse_html(response.body)
|
raise InfoException.new("This channel does not exist.")
|
||||||
|
|
||||||
ucid = html.xpath_node(%q(//link[@rel="canonical"])).try &.["href"].split("/")[-1]
|
|
||||||
if !ucid
|
|
||||||
env.response.status_code = 404
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
url = "/channel/#{ucid}"
|
ucid = resolved_url["endpoint"]["browseEndpoint"]["browseId"]
|
||||||
|
|
||||||
location = env.request.path.lchop?("/c/#{user}/")
|
selected_tab = env.request.path.split("/")[-1]
|
||||||
if location
|
if ["home", "videos", "playlists", "community", "channels", "about"].includes? selected_tab
|
||||||
url += "/#{location}"
|
url = "/channel/#{ucid}/#{selected_tab}"
|
||||||
|
else
|
||||||
|
url = "/channel/#{ucid}"
|
||||||
end
|
end
|
||||||
|
|
||||||
if env.params.query.size > 0
|
if env.params.query.size > 0
|
||||||
|
Loading…
Reference in New Issue
Block a user