Invidious is an alternative front-end to YouTube
Can fetch related channels using just the channel ucid]
matthewmcgarveydc62b6ffdb43
diff --git a/src/invidious/channels/about.cr b/src/invidious/channels/about.crindex 48f2d4d2..8cae7ae2 100644--- a/src/invidious/channels/about.cr+++ b/src/invidious/channels/about.cr@@ -12,13 +12,8 @@ record AboutChannel,joined : Time,is_family_friendly : Bool,allowed_regions : Array(String),- related_channels : RelatedChannels?,tabs : Array(String)-record RelatedChannels,- browse_id : String,- params : String?-record AboutRelatedChannel,ucid : String,author : String,@@ -47,7 +42,6 @@ def get_about_info(ucid, locale) : AboutChannelauto_generated = trueend- related_channels = nilif auto_generatedauthor = initdata["header"]["interactiveTabbedHeaderRenderer"]["title"]["simpleText"].as_sauthor_url = initdata["microformat"]["microformatDataRenderer"]["urlCanonical"].as_s@@ -82,15 +76,6 @@ def get_about_info(ucid, locale) : AboutChannelis_family_friendly = initdata["microformat"]["microformatDataRenderer"]["familySafe"].as_boolallowed_regions = initdata["microformat"]["microformatDataRenderer"]["availableCountries"].as_a.map(&.as_s)-- tabs = initdata.dig("contents", "twoColumnBrowseResultsRenderer", "tabs").as_a- if tab = tabs.find { |tab| tab.dig?("tabRenderer", "title").try(&.as_s?) == "Channels" }- browse_id = tab.dig?("tabRenderer", "endpoint", "browseEndpoint", "browseId").try(&.as_s?)- params = tab.dig?("tabRenderer", "endpoint", "browseEndpoint", "params").try(&.as_s?)- if browse_id- related_channels = RelatedChannels.new(browse_id: browse_id, params: params)- end- endendtotal_views = 0_i64@@ -142,13 +127,13 @@ def get_about_info(ucid, locale) : AboutChanneljoined: joined,is_family_friendly: is_family_friendly,allowed_regions: allowed_regions,- related_channels: related_channels,tabs: tabs,)end-def fetch_related_channels(related_channels : RelatedChannels) : Array(AboutRelatedChannel)- channels = YoutubeAPI.browse(browse_id: related_channels.browse_id, params: related_channels.params || "")+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::Anytab = tabs.find { |tab| tab.dig?("tabRenderer", "title").try(&.as_s?) == "Channels" }diff --git a/src/invidious/routes/api/v1/channels.cr b/src/invidious/routes/api/v1/channels.crindex d09641e6..322ac42e 100644--- a/src/invidious/routes/api/v1/channels.cr+++ b/src/invidious/routes/api/v1/channels.cr@@ -96,23 +96,21 @@ module Invidious::Routes::API::V1::Channelsjson.field "relatedChannels" dojson.array do- if related_channels = channel.related_channels- fetch_related_channels(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+ fetch_related_channels(channel).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", qualityendendend