Skip to content

Commit 170e754

Browse files
authored
Merge pull request #2868 from SamantazFox/related-channels-items-fix
Related channel may contain a continuation entry
2 parents 6a75fa0 + 698a6f3 commit 170e754

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

src/invidious/channels/about.cr

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,32 @@ def fetch_related_channels(about_channel : AboutChannel) : Array(AboutRelatedCha
140140

141141
return [] of AboutRelatedChannel if tab.nil?
142142

143-
items = tab.dig?("tabRenderer", "content", "sectionListRenderer", "contents", 0, "itemSectionRenderer", "contents", 0, "gridRenderer", "items").try(&.as_a?) || [] of JSON::Any
144-
145-
items.map do |item|
146-
related_id = item.dig("gridChannelRenderer", "channelId").as_s
147-
related_title = item.dig("gridChannelRenderer", "title", "simpleText").as_s
148-
related_author_url = item.dig("gridChannelRenderer", "navigationEndpoint", "browseEndpoint", "canonicalBaseUrl").as_s
149-
related_author_thumbnail = item.dig("gridChannelRenderer", "thumbnail", "thumbnails", -1, "url").as_s
150-
151-
AboutRelatedChannel.new(
143+
items = tab.dig?(
144+
"tabRenderer", "content",
145+
"sectionListRenderer", "contents", 0,
146+
"itemSectionRenderer", "contents", 0,
147+
"gridRenderer", "items"
148+
).try &.as_a?
149+
150+
related = [] of AboutRelatedChannel
151+
return related if (items.nil? || items.empty?)
152+
153+
items.each do |item|
154+
renderer = item["gridChannelRenderer"]?
155+
next if !renderer
156+
157+
related_id = renderer.dig("channelId").as_s
158+
related_title = renderer.dig("title", "simpleText").as_s
159+
related_author_url = renderer.dig("navigationEndpoint", "browseEndpoint", "canonicalBaseUrl").as_s
160+
related_author_thumbnail = HelperExtractors.get_thumbnails(renderer)
161+
162+
related << AboutRelatedChannel.new(
152163
ucid: related_id,
153164
author: related_title,
154165
author_url: related_author_url,
155166
author_thumbnail: related_author_thumbnail,
156167
)
157168
end
169+
170+
return related
158171
end

src/invidious/routes/api/v1/channels.cr

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,14 @@ module Invidious::Routes::API::V1::Channels
9696

9797
json.field "relatedChannels" do
9898
json.array do
99-
fetch_related_channels(channel).each do |related_channel|
99+
# Fetch related channels
100+
begin
101+
related_channels = fetch_related_channels(channel)
102+
rescue ex
103+
related_channels = [] of AboutRelatedChannel
104+
end
105+
106+
related_channels.each do |related_channel|
100107
json.object do
101108
json.field "author", related_channel.author
102109
json.field "authorId", related_channel.ucid
@@ -118,7 +125,8 @@ module Invidious::Routes::API::V1::Channels
118125
end
119126
end
120127
end
121-
end
128+
end # relatedChannels
129+
122130
end
123131
end
124132
end

0 commit comments

Comments
 (0)