Invidious is an alternative front-end to YouTube
frontend: Add support for the "featured channels" page
Samantaz Fox4e3a9306260b
diff --git a/locales/en-US.json b/locales/en-US.jsonindex 44b40c24..12955665 100644--- a/locales/en-US.json+++ b/locales/en-US.json@@ -475,5 +475,6 @@"channel_tab_shorts_label": "Shorts","channel_tab_streams_label": "Livestreams","channel_tab_playlists_label": "Playlists",- "channel_tab_community_label": "Community"+ "channel_tab_community_label": "Community",+ "channel_tab_channels_label": "Channels"}diff --git a/src/invidious/channels/about.cr b/src/invidious/channels/about.crindex 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) : AboutChannelbegin# "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), continuationenddiff --git a/src/invidious/frontend/channel_page.cr b/src/invidious/frontend/channel_page.crindex 7ac0e071..53745dd5 100644--- a/src/invidious/frontend/channel_page.cr+++ b/src/invidious/frontend/channel_page.cr@@ -7,6 +7,7 @@ module Invidious::Frontend::ChannelPageStreamsPlaylistsCommunity+ Channelsenddef 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.crindex 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::Channelsjson.array do# Fetch related channelsbegin- related_channels = fetch_related_channels(channel)+ related_channels, _ = fetch_related_channels(channel)rescue ex- related_channels = [] of AboutRelatedChannel+ related_channels = [] of SearchChannelendrelated_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)endendend # relatedChannelsdiff --git a/src/invidious/routes/channels.cr b/src/invidious/routes/channels.crindex 77d309fb..d3969d29 100644--- a/src/invidious/routes/channels.cr+++ b/src/invidious/routes/channels.cr@@ -147,6 +147,26 @@ module Invidious::Routes::Channelstemplated "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.crindex 0e6fba21..84dbed5b 100644--- a/src/invidious/routing.cr+++ b/src/invidious/routing.cr@@ -119,6 +119,7 @@ module Invidious::Routingget "/channel/:ucid/streams", Routes::Channels, :streamsget "/channel/:ucid/playlists", Routes::Channels, :playlistsget "/channel/:ucid/community", Routes::Channels, :community+ get "/channel/:ucid/channels", Routes::Channels, :channelsget "/channel/:ucid/about", Routes::Channels, :aboutget "/channel/:ucid/live", Routes::Channels, :liveget "/user/:user/live", Routes::Channels, :livediff --git a/src/invidious/views/channel.ecr b/src/invidious/views/channel.ecrindex 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