summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2022-02-07 00:37:47 +0100
committerSamantaz Fox <coding@samantaz.fr>2022-02-07 00:37:47 +0100
commit1668e4187ee1c1432e9af7b71bb266be60ca72e1 (patch)
tree784e5945e44590ab68d80732480e49e639bf5064 /src
parentdf599c0fc3226cdb5ce4cccfd26c02228976cac3 (diff)
downloadinvidious-1668e4187ee1c1432e9af7b71bb266be60ca72e1.tar.gz
invidious-1668e4187ee1c1432e9af7b71bb266be60ca72e1.tar.bz2
invidious-1668e4187ee1c1432e9af7b71bb266be60ca72e1.zip
Related channel may contain a continuation entry
Diffstat (limited to 'src')
-rw-r--r--src/invidious/channels/about.cr31
-rw-r--r--src/invidious/routes/api/v1/channels.cr8
2 files changed, 28 insertions, 11 deletions
diff --git a/src/invidious/channels/about.cr b/src/invidious/channels/about.cr
index 0f3928f5..4f82a0f1 100644
--- a/src/invidious/channels/about.cr
+++ b/src/invidious/channels/about.cr
@@ -140,19 +140,32 @@ def fetch_related_channels(about_channel : AboutChannel) : Array(AboutRelatedCha
return [] of AboutRelatedChannel if tab.nil?
- items = tab.dig?("tabRenderer", "content", "sectionListRenderer", "contents", 0, "itemSectionRenderer", "contents", 0, "gridRenderer", "items").try(&.as_a?) || [] of JSON::Any
-
- items.map do |item|
- related_id = item.dig("gridChannelRenderer", "channelId").as_s
- related_title = item.dig("gridChannelRenderer", "title", "simpleText").as_s
- related_author_url = item.dig("gridChannelRenderer", "navigationEndpoint", "browseEndpoint", "canonicalBaseUrl").as_s
- related_author_thumbnail = item.dig("gridChannelRenderer", "thumbnail", "thumbnails", -1, "url").as_s
-
- AboutRelatedChannel.new(
+ 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,
)
end
+
+ return related
end
diff --git a/src/invidious/routes/api/v1/channels.cr b/src/invidious/routes/api/v1/channels.cr
index 3e55b412..83c6db04 100644
--- a/src/invidious/routes/api/v1/channels.cr
+++ b/src/invidious/routes/api/v1/channels.cr
@@ -96,7 +96,10 @@ module Invidious::Routes::API::V1::Channels
json.field "relatedChannels" do
json.array do
- fetch_related_channels(channel).each do |related_channel|
+ # Fetch related channels
+ related_channels = fetch_related_channels(channel)
+
+ related_channels.each do |related_channel|
json.object do
json.field "author", related_channel.author
json.field "authorId", related_channel.ucid
@@ -118,7 +121,8 @@ module Invidious::Routes::API::V1::Channels
end
end
end
- end
+ end # relatedChannels
+
end
end
end