summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2022-12-05 00:50:04 +0100
committerSamantaz Fox <coding@samantaz.fr>2022-12-22 16:13:35 +0100
commit4e3a9306260b737e2d13c6a763899b946a6ecfbb (patch)
treeabcb5c701d44b50d762ce91078bd081422f54b6a /src
parentb6a4de66a5414f8ae790033fc3fc9e9fda70a860 (diff)
downloadinvidious-4e3a9306260b737e2d13c6a763899b946a6ecfbb.tar.gz
invidious-4e3a9306260b737e2d13c6a763899b946a6ecfbb.tar.bz2
invidious-4e3a9306260b737e2d13c6a763899b946a6ecfbb.zip
frontend: Add support for the "featured channels" page
Diffstat (limited to 'src')
-rw-r--r--src/invidious/channels/about.cr50
-rw-r--r--src/invidious/frontend/channel_page.cr1
-rw-r--r--src/invidious/routes/api/v1/channels.cr24
-rw-r--r--src/invidious/routes/channels.cr20
-rw-r--r--src/invidious/routing.cr1
-rw-r--r--src/invidious/views/channel.ecr1
6 files changed, 35 insertions, 62 deletions
diff --git a/src/invidious/channels/about.cr b/src/invidious/channels/about.cr
index 09c3427a..0054f8f2 100644
--- a/src/invidious/channels/about.cr
+++ b/src/invidious/channels/about.cr
@@ -16,12 +16,6 @@ record AboutChannel,
tabs : Array(String),
verified : Bool
-record AboutRelatedChannel,
- ucid : String,
- author : String,
- author_url : String,
- author_thumbnail : String
-
def get_about_info(ucid, locale) : AboutChannel
begin
# "EgVhYm91dA==" is the base64-encoded protobuf object {"2:string":"about"}
@@ -165,41 +159,15 @@ def get_about_info(ucid, locale) : AboutChannel
)
end
-def fetch_related_channels(about_channel : AboutChannel) : Array(AboutRelatedChannel)
- # params is {"2:string":"channels"} encoded
- channels = YoutubeAPI.browse(browse_id: about_channel.ucid, params: "EghjaGFubmVscw%3D%3D")
-
- tabs = channels.dig?("contents", "twoColumnBrowseResultsRenderer", "tabs").try(&.as_a?) || [] of JSON::Any
- tab = tabs.find(&.dig?("tabRenderer", "title").try(&.as_s?).try(&.== "Channels"))
-
- return [] of AboutRelatedChannel if tab.nil?
-
- items = tab.dig?(
- "tabRenderer", "content",
- "sectionListRenderer", "contents", 0,
- "itemSectionRenderer", "contents", 0,
- "gridRenderer", "items"
- ).try &.as_a?
-
- related = [] of AboutRelatedChannel
- return related if (items.nil? || items.empty?)
-
- items.each do |item|
- renderer = item["gridChannelRenderer"]?
- next if !renderer
-
- related_id = renderer.dig("channelId").as_s
- related_title = renderer.dig("title", "simpleText").as_s
- related_author_url = renderer.dig("navigationEndpoint", "browseEndpoint", "canonicalBaseUrl").as_s
- related_author_thumbnail = HelperExtractors.get_thumbnails(renderer)
-
- related << AboutRelatedChannel.new(
- ucid: related_id,
- author: related_title,
- author_url: related_author_url,
- author_thumbnail: related_author_thumbnail,
- )
+def fetch_related_channels(about_channel : AboutChannel, continuation : String? = nil) : {Array(SearchChannel), String?}
+ if continuation.nil?
+ # params is {"2:string":"channels"} encoded
+ initial_data = YoutubeAPI.browse(browse_id: about_channel.ucid, params: "EghjaGFubmVscw%3D%3D")
+ else
+ initial_data = YoutubeAPI.browse(continuation)
end
- return related
+ items, continuation = extract_items(initial_data)
+
+ return items.select(SearchChannel), continuation
end
diff --git a/src/invidious/frontend/channel_page.cr b/src/invidious/frontend/channel_page.cr
index 7ac0e071..53745dd5 100644
--- a/src/invidious/frontend/channel_page.cr
+++ b/src/invidious/frontend/channel_page.cr
@@ -7,6 +7,7 @@ module Invidious::Frontend::ChannelPage
Streams
Playlists
Community
+ Channels
end
def generate_tabs_links(locale : String, channel : AboutChannel, selected_tab : TabsAvailable)
diff --git a/src/invidious/routes/api/v1/channels.cr b/src/invidious/routes/api/v1/channels.cr
index 4e92b54e..28ccdab9 100644
--- a/src/invidious/routes/api/v1/channels.cr
+++ b/src/invidious/routes/api/v1/channels.cr
@@ -102,31 +102,13 @@ module Invidious::Routes::API::V1::Channels
json.array do
# Fetch related channels
begin
- related_channels = fetch_related_channels(channel)
+ related_channels, _ = fetch_related_channels(channel)
rescue ex
- related_channels = [] of AboutRelatedChannel
+ related_channels = [] of SearchChannel
end
related_channels.each do |related_channel|
- json.object do
- json.field "author", related_channel.author
- json.field "authorId", related_channel.ucid
- json.field "authorUrl", related_channel.author_url
-
- json.field "authorThumbnails" do
- json.array do
- qualities = {32, 48, 76, 100, 176, 512}
-
- qualities.each do |quality|
- json.object do
- json.field "url", related_channel.author_thumbnail.gsub(/=\d+/, "=s#{quality}")
- json.field "width", quality
- json.field "height", quality
- end
- end
- end
- end
- end
+ related_channel.to_json(locale, json)
end
end
end # relatedChannels
diff --git a/src/invidious/routes/channels.cr b/src/invidious/routes/channels.cr
index 77d309fb..d3969d29 100644
--- a/src/invidious/routes/channels.cr
+++ b/src/invidious/routes/channels.cr
@@ -147,6 +147,26 @@ module Invidious::Routes::Channels
templated "community"
end
+ def self.channels(env)
+ data = self.fetch_basic_information(env)
+ return data if !data.is_a?(Tuple)
+
+ locale, user, subscriptions, continuation, ucid, channel = data
+
+ if channel.auto_generated
+ return env.redirect "/channel/#{channel.ucid}"
+ end
+
+ items, next_continuation = fetch_related_channels(channel, continuation)
+
+ # Featured/related channels can't be sorted
+ sort_options = [] of String
+ sort_by = nil
+
+ selected_tab = Frontend::ChannelPage::TabsAvailable::Channels
+ templated "channel"
+ end
+
def self.about(env)
data = self.fetch_basic_information(env)
if !data.is_a?(Tuple)
diff --git a/src/invidious/routing.cr b/src/invidious/routing.cr
index 0e6fba21..84dbed5b 100644
--- a/src/invidious/routing.cr
+++ b/src/invidious/routing.cr
@@ -119,6 +119,7 @@ module Invidious::Routing
get "/channel/:ucid/streams", Routes::Channels, :streams
get "/channel/:ucid/playlists", Routes::Channels, :playlists
get "/channel/:ucid/community", Routes::Channels, :community
+ get "/channel/:ucid/channels", Routes::Channels, :channels
get "/channel/:ucid/about", Routes::Channels, :about
get "/channel/:ucid/live", Routes::Channels, :live
get "/user/:user/live", Routes::Channels, :live
diff --git a/src/invidious/views/channel.ecr b/src/invidious/views/channel.ecr
index 039f8752..a29315ef 100644
--- a/src/invidious/views/channel.ecr
+++ b/src/invidious/views/channel.ecr
@@ -8,6 +8,7 @@
when .shorts? then "/channel/#{ucid}/shorts"
when .streams? then "/channel/#{ucid}/streams"
when .playlists? then "/channel/#{ucid}/playlists"
+ when .channels? then "/channel/#{ucid}/channels"
else
"/channel/#{ucid}"
end