Skip to content

Commit 88856fd

Browse files
Add Courses to channel page and channel API
1 parent 164d764 commit 88856fd

File tree

7 files changed

+65
-1
lines changed

7 files changed

+65
-1
lines changed

locales/en-US.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@
492492
"channel_tab_streams_label": "Livestreams",
493493
"channel_tab_podcasts_label": "Podcasts",
494494
"channel_tab_releases_label": "Releases",
495+
"channel_tab_courses_label": "Courses",
495496
"channel_tab_playlists_label": "Playlists",
496497
"channel_tab_community_label": "Community",
497498
"channel_tab_channels_label": "Channels",

src/invidious/channels/playlists.cr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,12 @@ def fetch_channel_releases(ucid, author, continuation)
4444
end
4545
return extract_items(initial_data, author, ucid)
4646
end
47+
48+
def fetch_channel_courses(ucid, author, continuation)
49+
if continuation
50+
initial_data = YoutubeAPI.browse(continuation)
51+
else
52+
initial_data = YoutubeAPI.browse(ucid, params: "Egdjb3Vyc2Vz8gYFCgPCAQA%3D")
53+
end
54+
return extract_items(initial_data, author, ucid)
55+
end

src/invidious/frontend/channel_page.cr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Invidious::Frontend::ChannelPage
77
Streams
88
Podcasts
99
Releases
10+
Courses
1011
Playlists
1112
Community
1213
Channels

src/invidious/routes/api/v1/channels.cr

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,36 @@ module Invidious::Routes::API::V1::Channels
368368
end
369369
end
370370

371+
def self.courses(env)
372+
locale = env.get("preferences").as(Preferences).locale
373+
374+
env.response.content_type = "application/json"
375+
376+
ucid = env.params.url["ucid"]
377+
continuation = env.params.query["continuation"]?
378+
379+
# Use the macro defined above
380+
channel = nil # Make the compiler happy
381+
get_channel()
382+
383+
items, next_continuation = fetch_channel_courses(channel.ucid, channel.author, continuation)
384+
385+
JSON.build do |json|
386+
json.object do
387+
json.field "playlists" do
388+
json.array do
389+
items.each do |item|
390+
item.to_json(locale, json) if item.is_a?(SearchPlaylist)
391+
end
392+
end
393+
end
394+
395+
json.field "continuation", next_continuation if next_continuation
396+
end
397+
end
398+
end
399+
400+
371401
def self.community(env)
372402
locale = env.get("preferences").as(Preferences).locale
373403

src/invidious/routes/channels.cr

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,26 @@ module Invidious::Routes::Channels
197197
templated "channel"
198198
end
199199

200+
def self.courses(env)
201+
data = self.fetch_basic_information(env)
202+
return data if !data.is_a?(Tuple)
203+
204+
locale, user, subscriptions, continuation, ucid, channel = data
205+
206+
sort_by = ""
207+
sort_options = [] of String
208+
209+
items, next_continuation = fetch_channel_courses(
210+
channel.ucid, channel.author, continuation
211+
)
212+
213+
items = items.select(SearchPlaylist)
214+
items.each(&.author = "")
215+
216+
selected_tab = Frontend::ChannelPage::TabsAvailable::Courses
217+
templated "channel"
218+
end
219+
200220
def self.community(env)
201221
data = self.fetch_basic_information(env)
202222
if !data.is_a?(Tuple)
@@ -307,7 +327,7 @@ module Invidious::Routes::Channels
307327

308328
private KNOWN_TABS = {
309329
"home", "videos", "shorts", "streams", "podcasts",
310-
"releases", "playlists", "community", "channels", "about",
330+
"releases", "courses", "playlists", "community", "channels", "about",
311331
}
312332

313333
# Redirects brand url channels to a normal /channel/:ucid route

src/invidious/routing.cr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ module Invidious::Routing
120120
get "/channel/:ucid/streams", Routes::Channels, :streams
121121
get "/channel/:ucid/podcasts", Routes::Channels, :podcasts
122122
get "/channel/:ucid/releases", Routes::Channels, :releases
123+
get "/channel/:ucid/courses", Routes::Channels, :courses
123124
get "/channel/:ucid/playlists", Routes::Channels, :playlists
124125
get "/channel/:ucid/community", Routes::Channels, :community
125126
get "/channel/:ucid/channels", Routes::Channels, :channels
@@ -249,6 +250,7 @@ module Invidious::Routing
249250
get "/api/v1/channels/:ucid/streams", {{namespace}}::Channels, :streams
250251
get "/api/v1/channels/:ucid/podcasts", {{namespace}}::Channels, :podcasts
251252
get "/api/v1/channels/:ucid/releases", {{namespace}}::Channels, :releases
253+
get "/api/v1/channels/:ucid/courses", {{namespace}}::Channels, :courses
252254
get "/api/v1/channels/:ucid/playlists", {{namespace}}::Channels, :playlists
253255
get "/api/v1/channels/:ucid/community", {{namespace}}::Channels, :community
254256
get "/api/v1/channels/:ucid/channels", {{namespace}}::Channels, :channels

src/invidious/views/channel.ecr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
when .channels? then "/channel/#{ucid}/channels"
1212
when .podcasts? then "/channel/#{ucid}/podcasts"
1313
when .releases? then "/channel/#{ucid}/releases"
14+
when .courses? then "/channel/#{ucid}/courses"
1415
else
1516
"/channel/#{ucid}"
1617
end

0 commit comments

Comments
 (0)