mirror of
https://github.com/iv-org/invidious
synced 2024-11-27 21:43:28 +01:00
Can fetch related channels using just the channel ucid]
This commit is contained in:
parent
4962c00ba8
commit
dc62b6ffdb
@ -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) : AboutChannel
|
||||
auto_generated = true
|
||||
end
|
||||
|
||||
related_channels = nil
|
||||
if auto_generated
|
||||
author = initdata["header"]["interactiveTabbedHeaderRenderer"]["title"]["simpleText"].as_s
|
||||
author_url = initdata["microformat"]["microformatDataRenderer"]["urlCanonical"].as_s
|
||||
@ -82,15 +76,6 @@ def get_about_info(ucid, locale) : AboutChannel
|
||||
|
||||
is_family_friendly = initdata["microformat"]["microformatDataRenderer"]["familySafe"].as_bool
|
||||
allowed_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
|
||||
end
|
||||
end
|
||||
|
||||
total_views = 0_i64
|
||||
@ -142,13 +127,13 @@ def get_about_info(ucid, locale) : AboutChannel
|
||||
joined: 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::Any
|
||||
tab = tabs.find { |tab| tab.dig?("tabRenderer", "title").try(&.as_s?) == "Channels" }
|
||||
|
@ -96,8 +96,7 @@ module Invidious::Routes::API::V1::Channels
|
||||
|
||||
json.field "relatedChannels" do
|
||||
json.array do
|
||||
if related_channels = channel.related_channels
|
||||
fetch_related_channels(related_channels).each do |related_channel|
|
||||
fetch_related_channels(channel).each do |related_channel|
|
||||
json.object do
|
||||
json.field "author", related_channel.author
|
||||
json.field "authorId", related_channel.ucid
|
||||
@ -123,7 +122,6 @@ module Invidious::Routes::API::V1::Channels
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.latest(env)
|
||||
locale = env.get("preferences").as(Preferences).locale
|
||||
|
Loading…
Reference in New Issue
Block a user