diff options
| author | matthewmcgarvey <matthewmcgarvey14@gmail.com> | 2022-02-23 22:41:34 -0600 |
|---|---|---|
| committer | matthewmcgarvey <matthewmcgarvey14@gmail.com> | 2022-02-23 22:41:34 -0600 |
| commit | e215a20a0ac3dd4a3141f842ec6dd90b54cb67c3 (patch) | |
| tree | 5ada0432ba96c940f64ece42b599545c41a52b4b /src | |
| parent | 919413e2b90371d63d88c86305575c17cef6445d (diff) | |
| download | invidious-e215a20a0ac3dd4a3141f842ec6dd90b54cb67c3.tar.gz invidious-e215a20a0ac3dd4a3141f842ec6dd90b54cb67c3.tar.bz2 invidious-e215a20a0ac3dd4a3141f842ec6dd90b54cb67c3.zip | |
Move live endpoints into Channels route
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious.cr | 7 | ||||
| -rw-r--r-- | src/invidious/routes/channels.cr | 33 | ||||
| -rw-r--r-- | src/invidious/routes/live.cr | 34 |
3 files changed, 36 insertions, 38 deletions
diff --git a/src/invidious.cr b/src/invidious.cr index 140a9f7b..e32c1086 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -324,6 +324,9 @@ end Invidious::Routing.get "/channel/:ucid/playlists", Invidious::Routes::Channels, :playlists Invidious::Routing.get "/channel/:ucid/community", Invidious::Routes::Channels, :community Invidious::Routing.get "/channel/:ucid/about", Invidious::Routes::Channels, :about + Invidious::Routing.get "/channel/:ucid/live", Invidious::Routes::Channels, :live + Invidious::Routing.get "/user/:user/live", Invidious::Routes::Channels, :live + Invidious::Routing.get "/c/:user/live", Invidious::Routes::Channels, :live ["", "/videos", "/playlists", "/community", "/about"].each do |path| # /c/LinusTechTips @@ -400,10 +403,6 @@ Invidious::Routing.get "/s_p/:id/:name", Invidious::Routes::Images, :s_p_image Invidious::Routing.get "/yts/img/:name", Invidious::Routes::Images, :yts_image Invidious::Routing.get "/vi/:id/:name", Invidious::Routes::Images, :thumbnails -Invidious::Routing.get "/channel/:ucid/live", Invidious::Routes::Live, :check -Invidious::Routing.get "/user/:user/live", Invidious::Routes::Live, :check -Invidious::Routing.get "/c/:user/live", Invidious::Routes::Live, :check - # API routes (macro) define_v1_api_routes() Invidious::Routing.get "/api/v1/auth/notifications", Invidious::Routes::API::V1::Authenticated, :notifications_get diff --git a/src/invidious/routes/channels.cr b/src/invidious/routes/channels.cr index 6cb1e1f7..cd2e3323 100644 --- a/src/invidious/routes/channels.cr +++ b/src/invidious/routes/channels.cr @@ -147,6 +147,39 @@ module Invidious::Routes::Channels end end + def self.live(env) + locale = env.get("preferences").as(Preferences).locale + + # Appears to be a bug in routing, having several routes configured + # as `/a/:a`, `/b/:a`, `/c/:a` results in 404 + value = env.request.resource.split("/")[2] + body = "" + {"channel", "user", "c"}.each do |type| + response = YT_POOL.client &.get("/#{type}/#{value}/live?disable_polymer=1") + if response.status_code == 200 + body = response.body + end + end + + video_id = body.match(/'VIDEO_ID': "(?<id>[a-zA-Z0-9_-]{11})"/).try &.["id"]? + if video_id + params = [] of String + env.params.query.each do |k, v| + params << "#{k}=#{v}" + end + params = params.join("&") + + url = "/watch?v=#{video_id}" + if !params.empty? + url += "&#{params}" + end + + env.redirect url + else + env.redirect "/channel/#{value}" + end + end + private def self.fetch_basic_information(env) locale = env.get("preferences").as(Preferences).locale diff --git a/src/invidious/routes/live.cr b/src/invidious/routes/live.cr deleted file mode 100644 index e55111ce..00000000 --- a/src/invidious/routes/live.cr +++ /dev/null @@ -1,34 +0,0 @@ -module Invidious::Routes::Live - def self.check(env) - locale = env.get("preferences").as(Preferences).locale - - # Appears to be a bug in routing, having several routes configured - # as `/a/:a`, `/b/:a`, `/c/:a` results in 404 - value = env.request.resource.split("/")[2] - body = "" - {"channel", "user", "c"}.each do |type| - response = YT_POOL.client &.get("/#{type}/#{value}/live?disable_polymer=1") - if response.status_code == 200 - body = response.body - end - end - - video_id = body.match(/'VIDEO_ID': "(?<id>[a-zA-Z0-9_-]{11})"/).try &.["id"]? - if video_id - params = [] of String - env.params.query.each do |k, v| - params << "#{k}=#{v}" - end - params = params.join("&") - - url = "/watch?v=#{video_id}" - if !params.empty? - url += "&#{params}" - end - - env.redirect url - else - env.redirect "/channel/#{value}" - end - end -end |
