mirror of
https://github.com/iv-org/invidious.git
synced 2025-03-01 04:42:14 +00:00
Channels: Add Courses to channel page and channel API (#5158)
Closes #5144
This commit is contained in:
commit
9fbe3944b0
@ -493,6 +493,7 @@
|
|||||||
"channel_tab_streams_label": "Livestreams",
|
"channel_tab_streams_label": "Livestreams",
|
||||||
"channel_tab_podcasts_label": "Podcasts",
|
"channel_tab_podcasts_label": "Podcasts",
|
||||||
"channel_tab_releases_label": "Releases",
|
"channel_tab_releases_label": "Releases",
|
||||||
|
"channel_tab_courses_label": "Courses",
|
||||||
"channel_tab_playlists_label": "Playlists",
|
"channel_tab_playlists_label": "Playlists",
|
||||||
"channel_tab_community_label": "Community",
|
"channel_tab_community_label": "Community",
|
||||||
"channel_tab_channels_label": "Channels",
|
"channel_tab_channels_label": "Channels",
|
||||||
|
@ -44,3 +44,12 @@ def fetch_channel_releases(ucid, author, continuation)
|
|||||||
end
|
end
|
||||||
return extract_items(initial_data, author, ucid)
|
return extract_items(initial_data, author, ucid)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fetch_channel_courses(ucid, author, continuation)
|
||||||
|
if continuation
|
||||||
|
initial_data = YoutubeAPI.browse(continuation)
|
||||||
|
else
|
||||||
|
initial_data = YoutubeAPI.browse(ucid, params: "Egdjb3Vyc2Vz8gYFCgPCAQA%3D")
|
||||||
|
end
|
||||||
|
return extract_items(initial_data, author, ucid)
|
||||||
|
end
|
||||||
|
@ -7,6 +7,7 @@ module Invidious::Frontend::ChannelPage
|
|||||||
Streams
|
Streams
|
||||||
Podcasts
|
Podcasts
|
||||||
Releases
|
Releases
|
||||||
|
Courses
|
||||||
Playlists
|
Playlists
|
||||||
Community
|
Community
|
||||||
Channels
|
Channels
|
||||||
|
@ -368,6 +368,35 @@ module Invidious::Routes::API::V1::Channels
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.courses(env)
|
||||||
|
locale = env.get("preferences").as(Preferences).locale
|
||||||
|
|
||||||
|
env.response.content_type = "application/json"
|
||||||
|
|
||||||
|
ucid = env.params.url["ucid"]
|
||||||
|
continuation = env.params.query["continuation"]?
|
||||||
|
|
||||||
|
# Use the macro defined above
|
||||||
|
channel = nil # Make the compiler happy
|
||||||
|
get_channel()
|
||||||
|
|
||||||
|
items, next_continuation = fetch_channel_courses(channel.ucid, channel.author, continuation)
|
||||||
|
|
||||||
|
JSON.build do |json|
|
||||||
|
json.object do
|
||||||
|
json.field "playlists" do
|
||||||
|
json.array do
|
||||||
|
items.each do |item|
|
||||||
|
item.to_json(locale, json) if item.is_a?(SearchPlaylist)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
json.field "continuation", next_continuation if next_continuation
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.community(env)
|
def self.community(env)
|
||||||
locale = env.get("preferences").as(Preferences).locale
|
locale = env.get("preferences").as(Preferences).locale
|
||||||
|
|
||||||
|
@ -197,6 +197,26 @@ module Invidious::Routes::Channels
|
|||||||
templated "channel"
|
templated "channel"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.courses(env)
|
||||||
|
data = self.fetch_basic_information(env)
|
||||||
|
return data if !data.is_a?(Tuple)
|
||||||
|
|
||||||
|
locale, user, subscriptions, continuation, ucid, channel = data
|
||||||
|
|
||||||
|
sort_by = ""
|
||||||
|
sort_options = [] of String
|
||||||
|
|
||||||
|
items, next_continuation = fetch_channel_courses(
|
||||||
|
channel.ucid, channel.author, continuation
|
||||||
|
)
|
||||||
|
|
||||||
|
items = items.select(SearchPlaylist)
|
||||||
|
items.each(&.author = "")
|
||||||
|
|
||||||
|
selected_tab = Frontend::ChannelPage::TabsAvailable::Courses
|
||||||
|
templated "channel"
|
||||||
|
end
|
||||||
|
|
||||||
def self.community(env)
|
def self.community(env)
|
||||||
data = self.fetch_basic_information(env)
|
data = self.fetch_basic_information(env)
|
||||||
if !data.is_a?(Tuple)
|
if !data.is_a?(Tuple)
|
||||||
@ -307,7 +327,7 @@ module Invidious::Routes::Channels
|
|||||||
|
|
||||||
private KNOWN_TABS = {
|
private KNOWN_TABS = {
|
||||||
"home", "videos", "shorts", "streams", "podcasts",
|
"home", "videos", "shorts", "streams", "podcasts",
|
||||||
"releases", "playlists", "community", "channels", "about",
|
"releases", "courses", "playlists", "community", "channels", "about",
|
||||||
}
|
}
|
||||||
|
|
||||||
# Redirects brand url channels to a normal /channel/:ucid route
|
# Redirects brand url channels to a normal /channel/:ucid route
|
||||||
|
@ -120,6 +120,7 @@ module Invidious::Routing
|
|||||||
get "/channel/:ucid/streams", Routes::Channels, :streams
|
get "/channel/:ucid/streams", Routes::Channels, :streams
|
||||||
get "/channel/:ucid/podcasts", Routes::Channels, :podcasts
|
get "/channel/:ucid/podcasts", Routes::Channels, :podcasts
|
||||||
get "/channel/:ucid/releases", Routes::Channels, :releases
|
get "/channel/:ucid/releases", Routes::Channels, :releases
|
||||||
|
get "/channel/:ucid/courses", Routes::Channels, :courses
|
||||||
get "/channel/:ucid/playlists", Routes::Channels, :playlists
|
get "/channel/:ucid/playlists", Routes::Channels, :playlists
|
||||||
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
|
||||||
@ -250,6 +251,7 @@ module Invidious::Routing
|
|||||||
get "/api/v1/channels/:ucid/streams", {{namespace}}::Channels, :streams
|
get "/api/v1/channels/:ucid/streams", {{namespace}}::Channels, :streams
|
||||||
get "/api/v1/channels/:ucid/podcasts", {{namespace}}::Channels, :podcasts
|
get "/api/v1/channels/:ucid/podcasts", {{namespace}}::Channels, :podcasts
|
||||||
get "/api/v1/channels/:ucid/releases", {{namespace}}::Channels, :releases
|
get "/api/v1/channels/:ucid/releases", {{namespace}}::Channels, :releases
|
||||||
|
get "/api/v1/channels/:ucid/courses", {{namespace}}::Channels, :courses
|
||||||
get "/api/v1/channels/:ucid/playlists", {{namespace}}::Channels, :playlists
|
get "/api/v1/channels/:ucid/playlists", {{namespace}}::Channels, :playlists
|
||||||
get "/api/v1/channels/:ucid/community", {{namespace}}::Channels, :community
|
get "/api/v1/channels/:ucid/community", {{namespace}}::Channels, :community
|
||||||
get "/api/v1/channels/:ucid/channels", {{namespace}}::Channels, :channels
|
get "/api/v1/channels/:ucid/channels", {{namespace}}::Channels, :channels
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
when .channels? then "/channel/#{ucid}/channels"
|
when .channels? then "/channel/#{ucid}/channels"
|
||||||
when .podcasts? then "/channel/#{ucid}/podcasts"
|
when .podcasts? then "/channel/#{ucid}/podcasts"
|
||||||
when .releases? then "/channel/#{ucid}/releases"
|
when .releases? then "/channel/#{ucid}/releases"
|
||||||
|
when .courses? then "/channel/#{ucid}/courses"
|
||||||
else
|
else
|
||||||
"/channel/#{ucid}"
|
"/channel/#{ucid}"
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user