forked from midou/invidious
Routing: Add support for new routes (#4099)
This commit is contained in:
commit
eddb54adb1
@ -1,6 +1,12 @@
|
|||||||
{% skip_file if flag?(:api_only) %}
|
{% skip_file if flag?(:api_only) %}
|
||||||
|
|
||||||
module Invidious::Routes::Channels
|
module Invidious::Routes::Channels
|
||||||
|
# Redirection for unsupported routes ("tabs")
|
||||||
|
def self.redirect_home(env)
|
||||||
|
ucid = env.params.url["ucid"]
|
||||||
|
return env.redirect "/channel/#{URI.encode_www_form(ucid)}"
|
||||||
|
end
|
||||||
|
|
||||||
def self.home(env)
|
def self.home(env)
|
||||||
self.videos(env)
|
self.videos(env)
|
||||||
end
|
end
|
||||||
@ -217,6 +223,11 @@ module Invidious::Routes::Channels
|
|||||||
env.redirect "/channel/#{ucid}"
|
env.redirect "/channel/#{ucid}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private KNOWN_TABS = {
|
||||||
|
"home", "videos", "shorts", "streams", "podcasts",
|
||||||
|
"releases", "playlists", "community", "channels", "about",
|
||||||
|
}
|
||||||
|
|
||||||
# Redirects brand url channels to a normal /channel/:ucid route
|
# Redirects brand url channels to a normal /channel/:ucid route
|
||||||
def self.brand_redirect(env)
|
def self.brand_redirect(env)
|
||||||
locale = env.get("preferences").as(Preferences).locale
|
locale = env.get("preferences").as(Preferences).locale
|
||||||
@ -227,7 +238,10 @@ module Invidious::Routes::Channels
|
|||||||
yt_url_params = URI::Params.encode(env.params.query.to_h.select(["a", "u", "user"]))
|
yt_url_params = URI::Params.encode(env.params.query.to_h.select(["a", "u", "user"]))
|
||||||
|
|
||||||
# Retrieves URL params that only Invidious uses
|
# Retrieves URL params that only Invidious uses
|
||||||
invidious_url_params = URI::Params.encode(env.params.query.to_h.select!(["a", "u", "user"]))
|
invidious_url_params = env.params.query.dup
|
||||||
|
invidious_url_params.delete_all("a")
|
||||||
|
invidious_url_params.delete_all("u")
|
||||||
|
invidious_url_params.delete_all("user")
|
||||||
|
|
||||||
begin
|
begin
|
||||||
resolved_url = YoutubeAPI.resolve_url("https://youtube.com#{env.request.path}#{yt_url_params.size > 0 ? "?#{yt_url_params}" : ""}")
|
resolved_url = YoutubeAPI.resolve_url("https://youtube.com#{env.request.path}#{yt_url_params.size > 0 ? "?#{yt_url_params}" : ""}")
|
||||||
@ -236,14 +250,17 @@ module Invidious::Routes::Channels
|
|||||||
return error_template(404, translate(locale, "This channel does not exist."))
|
return error_template(404, translate(locale, "This channel does not exist."))
|
||||||
end
|
end
|
||||||
|
|
||||||
selected_tab = env.request.path.split("/")[-1]
|
selected_tab = env.params.url["tab"]?
|
||||||
if {"home", "videos", "shorts", "streams", "playlists", "community", "channels", "about"}.includes? selected_tab
|
|
||||||
|
if KNOWN_TABS.includes? selected_tab
|
||||||
url = "/channel/#{ucid}/#{selected_tab}"
|
url = "/channel/#{ucid}/#{selected_tab}"
|
||||||
else
|
else
|
||||||
url = "/channel/#{ucid}"
|
url = "/channel/#{ucid}"
|
||||||
end
|
end
|
||||||
|
|
||||||
env.redirect url
|
url += "?#{invidious_url_params}" if !invidious_url_params.empty?
|
||||||
|
|
||||||
|
return env.redirect url
|
||||||
end
|
end
|
||||||
|
|
||||||
# Handles redirects for the /profile endpoint
|
# Handles redirects for the /profile endpoint
|
||||||
|
@ -124,28 +124,41 @@ module Invidious::Routing
|
|||||||
get "/channel/:ucid/community", Routes::Channels, :community
|
get "/channel/:ucid/community", Routes::Channels, :community
|
||||||
get "/channel/:ucid/channels", Routes::Channels, :channels
|
get "/channel/:ucid/channels", Routes::Channels, :channels
|
||||||
get "/channel/:ucid/about", Routes::Channels, :about
|
get "/channel/:ucid/about", Routes::Channels, :about
|
||||||
|
|
||||||
get "/channel/:ucid/live", Routes::Channels, :live
|
get "/channel/:ucid/live", Routes::Channels, :live
|
||||||
get "/user/:user/live", Routes::Channels, :live
|
get "/user/:user/live", Routes::Channels, :live
|
||||||
get "/c/:user/live", Routes::Channels, :live
|
get "/c/:user/live", Routes::Channels, :live
|
||||||
|
|
||||||
{"", "/videos", "/shorts", "/streams", "/playlists", "/community", "/about"}.each do |path|
|
# Channel catch-all, to redirect future routes to the channel's home
|
||||||
|
# NOTE: defined last in order to be processed after the other routes
|
||||||
|
get "/channel/:ucid/*", Routes::Channels, :redirect_home
|
||||||
|
|
||||||
# /c/LinusTechTips
|
# /c/LinusTechTips
|
||||||
get "/c/:user#{path}", Routes::Channels, :brand_redirect
|
get "/c/:user", Routes::Channels, :brand_redirect
|
||||||
# /user/linustechtips | Not always the same as /c/
|
get "/c/:user/:tab", Routes::Channels, :brand_redirect
|
||||||
get "/user/:user#{path}", Routes::Channels, :brand_redirect
|
|
||||||
# /@LinusTechTips | Handle
|
# /user/linustechtips (Not always the same as /c/)
|
||||||
get "/@:user#{path}", Routes::Channels, :brand_redirect
|
get "/user/:user", Routes::Channels, :brand_redirect
|
||||||
|
get "/user/:user/:tab", Routes::Channels, :brand_redirect
|
||||||
|
|
||||||
|
# /@LinusTechTips (Handle)
|
||||||
|
get "/@:user", Routes::Channels, :brand_redirect
|
||||||
|
get "/@:user/:tab", Routes::Channels, :brand_redirect
|
||||||
|
|
||||||
# /attribution_link?a=anything&u=/channel/UCZYTClx2T1of7BRZ86-8fow
|
# /attribution_link?a=anything&u=/channel/UCZYTClx2T1of7BRZ86-8fow
|
||||||
get "/attribution_link#{path}", Routes::Channels, :brand_redirect
|
get "/attribution_link", Routes::Channels, :brand_redirect
|
||||||
|
get "/attribution_link/:tab", Routes::Channels, :brand_redirect
|
||||||
|
|
||||||
# /profile?user=linustechtips
|
# /profile?user=linustechtips
|
||||||
get "/profile/#{path}", Routes::Channels, :profile
|
get "/profile", Routes::Channels, :profile
|
||||||
end
|
get "/profile/*", Routes::Channels, :profile
|
||||||
end
|
end
|
||||||
|
|
||||||
def register_watch_routes
|
def register_watch_routes
|
||||||
get "/watch", Routes::Watch, :handle
|
get "/watch", Routes::Watch, :handle
|
||||||
post "/watch_ajax", Routes::Watch, :mark_watched
|
post "/watch_ajax", Routes::Watch, :mark_watched
|
||||||
get "/watch/:id", Routes::Watch, :redirect
|
get "/watch/:id", Routes::Watch, :redirect
|
||||||
|
get "/live/:id", Routes::Watch, :redirect
|
||||||
get "/shorts/:id", Routes::Watch, :redirect
|
get "/shorts/:id", Routes::Watch, :redirect
|
||||||
get "/clip/:clip", Routes::Watch, :clip
|
get "/clip/:clip", Routes::Watch, :clip
|
||||||
get "/w/:id", Routes::Watch, :redirect
|
get "/w/:id", Routes::Watch, :redirect
|
||||||
|
Loading…
Reference in New Issue
Block a user