mirror of
https://github.com/iv-org/invidious.git
synced 2024-12-02 03:31:20 +05:30
Merge pull request #2868 from SamantazFox/related-channels-items-fix
Related channel may contain a continuation entry
This commit is contained in:
commit
170e754998
@ -140,19 +140,32 @@ def fetch_related_channels(about_channel : AboutChannel) : Array(AboutRelatedCha
|
|||||||
|
|
||||||
return [] of AboutRelatedChannel if tab.nil?
|
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 = tab.dig?(
|
||||||
|
"tabRenderer", "content",
|
||||||
|
"sectionListRenderer", "contents", 0,
|
||||||
|
"itemSectionRenderer", "contents", 0,
|
||||||
|
"gridRenderer", "items"
|
||||||
|
).try &.as_a?
|
||||||
|
|
||||||
items.map do |item|
|
related = [] of AboutRelatedChannel
|
||||||
related_id = item.dig("gridChannelRenderer", "channelId").as_s
|
return related if (items.nil? || items.empty?)
|
||||||
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.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,
|
ucid: related_id,
|
||||||
author: related_title,
|
author: related_title,
|
||||||
author_url: related_author_url,
|
author_url: related_author_url,
|
||||||
author_thumbnail: related_author_thumbnail,
|
author_thumbnail: related_author_thumbnail,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return related
|
||||||
end
|
end
|
||||||
|
@ -96,7 +96,14 @@ module Invidious::Routes::API::V1::Channels
|
|||||||
|
|
||||||
json.field "relatedChannels" do
|
json.field "relatedChannels" do
|
||||||
json.array do
|
json.array do
|
||||||
fetch_related_channels(channel).each do |related_channel|
|
# Fetch related channels
|
||||||
|
begin
|
||||||
|
related_channels = fetch_related_channels(channel)
|
||||||
|
rescue ex
|
||||||
|
related_channels = [] of AboutRelatedChannel
|
||||||
|
end
|
||||||
|
|
||||||
|
related_channels.each do |related_channel|
|
||||||
json.object do
|
json.object do
|
||||||
json.field "author", related_channel.author
|
json.field "author", related_channel.author
|
||||||
json.field "authorId", related_channel.ucid
|
json.field "authorId", related_channel.ucid
|
||||||
@ -118,7 +125,8 @@ module Invidious::Routes::API::V1::Channels
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end # relatedChannels
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user