Invidious is an alternative front-end to YouTube
Add related_channels to /api/v1/channels
Omar Roth6033e8aed18f
diff --git a/src/invidious.cr b/src/invidious.crindex 863e2a9a..724ba3a6 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -2713,6 +2713,29 @@ get "/api/v1/channels/:ucid" do |env|is_family_friendly = channel_html.xpath_node(%q(//meta[@itemprop="isFamilyFriendly"])).not_nil!["content"] == "True"allowed_regions = channel_html.xpath_node(%q(//meta[@itemprop="regionsAllowed"])).not_nil!["content"].split(",")+ related_channels = channel_html.xpath_nodes(%q(//div[contains(@class, "branded-page-related-channels")]/ul/li))+ related_channels = related_channels.map do |node|+ related_id = node["data-external-id"]?+ related_id ||= ""++ anchor = node.xpath_node(%q(.//h3[contains(@class, "yt-lockup-title")]/a))+ related_title = anchor.try &.["title"]+ related_title ||= ""++ related_author_url = anchor.try &.["href"]+ related_author_url ||= ""++ related_author_thumbnail = node.xpath_node(%q(.//img)).try &.["data-thumb"]+ related_author_thumbnail ||= ""++ {+ id: related_id,+ author: related_title,+ author_url: related_author_url,+ author_thumbnail: related_author_thumbnail,+ }+ end+total_views = 0_i64sub_count = 0_i64joined = Time.unix(0)@@ -2815,6 +2838,32 @@ get "/api/v1/channels/:ucid" do |env|endendend++ json.field "relatedChannels" do+ json.array do+ related_channels.each do |related_channel|+ json.object do+ json.field "author", related_channel[:author]+ json.field "authorId", related_channel[:id]+ 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("=s48-", "=s#{quality}-")+ json.field "width", quality+ json.field "height", quality+ end+ end+ end+ end+ end+ end+ end+ endendend