summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2022-12-22 17:26:30 +0100
committerSamantaz Fox <coding@samantaz.fr>2022-12-22 17:26:30 +0100
commit69b8e0919fd0a410d35f5f5fccc4753f79faf940 (patch)
tree7270aeb35824ee0f363d2913a65d67b7996ea8e2 /src
parent4e3a9306260b737e2d13c6a763899b946a6ecfbb (diff)
downloadinvidious-69b8e0919fd0a410d35f5f5fccc4753f79faf940.tar.gz
invidious-69b8e0919fd0a410d35f5f5fccc4753f79faf940.tar.bz2
invidious-69b8e0919fd0a410d35f5f5fccc4753f79faf940.zip
api: Add support for the "featured channels" endpoint
Diffstat (limited to 'src')
-rw-r--r--src/invidious/routes/api/v1/channels.cr31
-rw-r--r--src/invidious/routing.cr1
2 files changed, 32 insertions, 0 deletions
diff --git a/src/invidious/routes/api/v1/channels.cr b/src/invidious/routes/api/v1/channels.cr
index 28ccdab9..ca2b2734 100644
--- a/src/invidious/routes/api/v1/channels.cr
+++ b/src/invidious/routes/api/v1/channels.cr
@@ -283,6 +283,37 @@ module Invidious::Routes::API::V1::Channels
end
end
+ def self.channels(env)
+ locale = env.get("preferences").as(Preferences).locale
+ ucid = env.params.url["ucid"]
+
+ env.response.content_type = "application/json"
+
+ # Use the macro defined above
+ channel = nil # Make the compiler happy
+ get_channel()
+
+ continuation = env.params.query["continuation"]?
+
+ begin
+ items, next_continuation = fetch_related_channels(channel, continuation)
+ rescue ex
+ return error_json(500, ex)
+ end
+
+ JSON.build do |json|
+ json.object do
+ json.field "relatedChannels" do
+ json.array do
+ items.each &.to_json(locale, json)
+ end
+ end
+
+ json.field "continuation", next_continuation if next_continuation
+ end
+ end
+ end
+
def self.search(env)
locale = env.get("preferences").as(Preferences).locale
region = env.params.query["region"]?
diff --git a/src/invidious/routing.cr b/src/invidious/routing.cr
index 84dbed5b..54bd82a4 100644
--- a/src/invidious/routing.cr
+++ b/src/invidious/routing.cr
@@ -225,6 +225,7 @@ module Invidious::Routing
get "/api/v1/channels/:ucid", {{namespace}}::Channels, :home
get "/api/v1/channels/:ucid/shorts", {{namespace}}::Channels, :shorts
get "/api/v1/channels/:ucid/streams", {{namespace}}::Channels, :streams
+ get "/api/v1/channels/:ucid/channels", {{namespace}}::Channels, :channels
{% for route in {"videos", "latest", "playlists", "community", "search"} %}
get "/api/v1/channels/#{{{route}}}/:ucid", {{namespace}}::Channels, :{{route}}