Invidious is an alternative front-end to YouTube
Move remaining routes to new structure
matthewmcgarvey3b1837a99b7a
diff --git a/src/invidious.cr b/src/invidious.crindex 24f49930..dc055e59 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -154,8 +154,8 @@ if CONFIG.popular_enabledInvidious::Jobs.register Invidious::Jobs::PullPopularVideosJob.new(PG_DB)end-connection_channel = Channel({Bool, Channel(PQ::Notification)}).new(32)-Invidious::Jobs.register Invidious::Jobs::NotificationJob.new(connection_channel, CONFIG.database_url)+CONNECTION_CHANNEL = Channel({Bool, Channel(PQ::Notification)}).new(32)+Invidious::Jobs.register Invidious::Jobs::NotificationJob.new(CONNECTION_CHANNEL, CONFIG.database_url)Invidious::Jobs.start_all@@ -360,6 +360,7 @@ endInvidious::Routing.post "/playlist_ajax", Invidious::Routes::Playlists, :playlist_ajaxInvidious::Routing.get "/playlist", Invidious::Routes::Playlists, :showInvidious::Routing.get "/mix", Invidious::Routes::Playlists, :mix+ Invidious::Routing.get "/watch_videos", Invidious::Routes::Playlists, :watch_videosInvidious::Routing.get "/opensearch.xml", Invidious::Routes::Search, :opensearchInvidious::Routing.get "/results", Invidious::Routes::Search, :results@@ -390,6 +391,8 @@ endInvidious::Routing.post "/subscription_ajax", Invidious::Routes::Subscriptions, :toggle_subscriptionInvidious::Routing.get "/subscription_manager", Invidious::Routes::Subscriptions, :subscription_manager++ Invidious::Routing.get "/Captcha", Invidious::Routes::Captcha, :get{% end %}Invidious::Routing.get "/ggpht/*", Invidious::Routes::Images, :ggpht@@ -405,53 +408,13 @@ 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+Invidious::Routing.post "/api/v1/auth/notifications", Invidious::Routes::API::V1::Authenticated, :notifications_post# Video playback (macros)define_api_manifest_routes()define_video_playback_routes()-# Authenticated endpoints--# The notification APIs can't be extracted yet-# due to the requirement of the `connection_channel`-# used by the `NotificationJob`--get "/api/v1/auth/notifications" do |env|- env.response.content_type = "text/event-stream"-- topics = env.params.query["topics"]?.try &.split(",").uniq.first(1000)- topics ||= [] of String-- create_notification_stream(env, topics, connection_channel)-end--post "/api/v1/auth/notifications" do |env|- env.response.content_type = "text/event-stream"-- topics = env.params.body["topics"]?.try &.split(",").uniq.first(1000)- topics ||= [] of String-- create_notification_stream(env, topics, connection_channel)-end--get "/Captcha" do |env|- headers = HTTP::Headers{":authority" => "accounts.google.com"}- response = YT_POOL.client &.get(env.request.resource, headers)- env.response.headers["Content-Type"] = response.headers["Content-Type"]- response.body-end--# Undocumented, creates anonymous playlist with specified 'video_ids', max 50 videos-get "/watch_videos" do |env|- response = YT_POOL.client &.get(env.request.resource)- if url = response.headers["Location"]?- url = URI.parse(url).request_target- next env.redirect url- end-- env.response.status_code = response.status_code-end-error 404 do |env|if md = env.request.path.match(/^\/(?<id>([a-zA-Z0-9_-]{11})|(\w+))$/)item = md["id"]diff --git a/src/invidious/routes/api/v1/authenticated.cr b/src/invidious/routes/api/v1/authenticated.crindex c27853ca..6ced4edb 100644--- a/src/invidious/routes/api/v1/authenticated.cr+++ b/src/invidious/routes/api/v1/authenticated.cr@@ -397,4 +397,22 @@ module Invidious::Routes::API::V1::Authenticatedenv.response.status_code = 204end++ def self.notifications_get(env)+ env.response.content_type = "text/event-stream"++ topics = env.params.query["topics"]?.try &.split(",").uniq.first(1000)+ topics ||= [] of String++ create_notification_stream(env, topics, CONNECTION_CHANNEL)+ end++ def self.notifications_post(env)+ env.response.content_type = "text/event-stream"++ topics = env.params.body["topics"]?.try &.split(",").uniq.first(1000)+ topics ||= [] of String++ create_notification_stream(env, topics, CONNECTION_CHANNEL)+ endenddiff --git a/src/invidious/routes/captcha.cr b/src/invidious/routes/captcha.crnew file mode 100644index 00000000..a1d95a4f--- /dev/null+++ b/src/invidious/routes/captcha.cr@@ -0,0 +1,8 @@+module Invidious::Routes::Captcha+ def self.get(env)+ headers = HTTP::Headers{":authority" => "accounts.google.com"}+ response = YT_POOL.client &.get(env.request.resource, headers)+ env.response.headers["Content-Type"] = response.headers["Content-Type"]+ response.body+ end+enddiff --git a/src/invidious/routes/playlists.cr b/src/invidious/routes/playlists.crindex 1ed29e79..dbeb4f97 100644--- a/src/invidious/routes/playlists.cr+++ b/src/invidious/routes/playlists.cr@@ -443,4 +443,15 @@ module Invidious::Routes::Playliststemplated "mix"end++ # Undocumented, creates anonymous playlist with specified 'video_ids', max 50 videos+ def self.watch_videos(env)+ response = YT_POOL.client &.get(env.request.resource)+ if url = response.headers["Location"]?+ url = URI.parse(url).request_target+ return env.redirect url+ end++ env.response.status_code = response.status_code+ endend