|
|
@ -1,33 +1,31 @@
|
|
|
|
# TODO: Refactor into either SearchChannel or InvidiousChannel
|
|
|
|
# TODO: Refactor into either SearchChannel or InvidiousChannel
|
|
|
|
struct AboutChannel
|
|
|
|
record AboutChannel,
|
|
|
|
include DB::Serializable
|
|
|
|
ucid : String,
|
|
|
|
|
|
|
|
author : String,
|
|
|
|
property ucid : String
|
|
|
|
auto_generated : Bool,
|
|
|
|
property author : String
|
|
|
|
author_url : String,
|
|
|
|
property auto_generated : Bool
|
|
|
|
author_thumbnail : String,
|
|
|
|
property author_url : String
|
|
|
|
banner : String?,
|
|
|
|
property author_thumbnail : String
|
|
|
|
description_html : String,
|
|
|
|
property banner : String?
|
|
|
|
total_views : Int64,
|
|
|
|
property description_html : String
|
|
|
|
sub_count : Int32,
|
|
|
|
property total_views : Int64
|
|
|
|
joined : Time,
|
|
|
|
property sub_count : Int32
|
|
|
|
is_family_friendly : Bool,
|
|
|
|
property joined : Time
|
|
|
|
allowed_regions : Array(String),
|
|
|
|
property is_family_friendly : Bool
|
|
|
|
related_channels : RelatedChannels?,
|
|
|
|
property allowed_regions : Array(String)
|
|
|
|
tabs : Array(String)
|
|
|
|
property related_channels : Array(AboutRelatedChannel)
|
|
|
|
|
|
|
|
property tabs : Array(String)
|
|
|
|
record RelatedChannels,
|
|
|
|
end
|
|
|
|
browse_id : String,
|
|
|
|
|
|
|
|
params : String?
|
|
|
|
struct AboutRelatedChannel
|
|
|
|
|
|
|
|
include DB::Serializable
|
|
|
|
record AboutRelatedChannel,
|
|
|
|
|
|
|
|
ucid : String,
|
|
|
|
property ucid : String
|
|
|
|
author : String,
|
|
|
|
property author : String
|
|
|
|
author_url : String,
|
|
|
|
property author_url : String
|
|
|
|
author_thumbnail : String
|
|
|
|
property author_thumbnail : String
|
|
|
|
|
|
|
|
end
|
|
|
|
def get_about_info(ucid, locale) : AboutChannel
|
|
|
|
|
|
|
|
|
|
|
|
def get_about_info(ucid, locale)
|
|
|
|
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
# "EgVhYm91dA==" is the base64-encoded protobuf object {"2:string":"about"}
|
|
|
|
# "EgVhYm91dA==" is the base64-encoded protobuf object {"2:string":"about"}
|
|
|
|
initdata = YoutubeAPI.browse(browse_id: ucid, params: "EgVhYm91dA==")
|
|
|
|
initdata = YoutubeAPI.browse(browse_id: ucid, params: "EgVhYm91dA==")
|
|
|
@ -49,6 +47,7 @@ def get_about_info(ucid, locale)
|
|
|
|
auto_generated = true
|
|
|
|
auto_generated = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
related_channels = nil
|
|
|
|
if auto_generated
|
|
|
|
if auto_generated
|
|
|
|
author = initdata["header"]["interactiveTabbedHeaderRenderer"]["title"]["simpleText"].as_s
|
|
|
|
author = initdata["header"]["interactiveTabbedHeaderRenderer"]["title"]["simpleText"].as_s
|
|
|
|
author_url = initdata["microformat"]["microformatDataRenderer"]["urlCanonical"].as_s
|
|
|
|
author_url = initdata["microformat"]["microformatDataRenderer"]["urlCanonical"].as_s
|
|
|
@ -63,8 +62,6 @@ def get_about_info(ucid, locale)
|
|
|
|
|
|
|
|
|
|
|
|
is_family_friendly = initdata["microformat"]["microformatDataRenderer"]["familySafe"].as_bool
|
|
|
|
is_family_friendly = initdata["microformat"]["microformatDataRenderer"]["familySafe"].as_bool
|
|
|
|
allowed_regions = initdata["microformat"]["microformatDataRenderer"]["availableCountries"].as_a.map(&.as_s)
|
|
|
|
allowed_regions = initdata["microformat"]["microformatDataRenderer"]["availableCountries"].as_a.map(&.as_s)
|
|
|
|
|
|
|
|
|
|
|
|
related_channels = [] of AboutRelatedChannel
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
|
author = initdata["metadata"]["channelMetadataRenderer"]["title"].as_s
|
|
|
|
author = initdata["metadata"]["channelMetadataRenderer"]["title"].as_s
|
|
|
|
author_url = initdata["metadata"]["channelMetadataRenderer"]["channelUrl"].as_s
|
|
|
|
author_url = initdata["metadata"]["channelMetadataRenderer"]["channelUrl"].as_s
|
|
|
@ -86,37 +83,14 @@ def get_about_info(ucid, locale)
|
|
|
|
is_family_friendly = initdata["microformat"]["microformatDataRenderer"]["familySafe"].as_bool
|
|
|
|
is_family_friendly = initdata["microformat"]["microformatDataRenderer"]["familySafe"].as_bool
|
|
|
|
allowed_regions = initdata["microformat"]["microformatDataRenderer"]["availableCountries"].as_a.map(&.as_s)
|
|
|
|
allowed_regions = initdata["microformat"]["microformatDataRenderer"]["availableCountries"].as_a.map(&.as_s)
|
|
|
|
|
|
|
|
|
|
|
|
related_channels = initdata["contents"]["twoColumnBrowseResultsRenderer"]
|
|
|
|
tabs = initdata.dig("contents", "twoColumnBrowseResultsRenderer", "tabs").as_a
|
|
|
|
.["secondaryContents"]?.try &.["browseSecondaryContentsRenderer"]["contents"][0]?
|
|
|
|
if tab = tabs.find { |tab| tab.dig?("tabRenderer", "title").try(&.as_s?) == "Channels" }
|
|
|
|
.try &.["verticalChannelSectionRenderer"]?.try &.["items"]?.try &.as_a.map do |node|
|
|
|
|
browse_id = tab.dig?("tabRenderer", "endpoint", "browseEndpoint", "browseId").try(&.as_s?)
|
|
|
|
renderer = node["miniChannelRenderer"]?
|
|
|
|
params = tab.dig?("tabRenderer", "endpoint", "browseEndpoint", "params").try(&.as_s?)
|
|
|
|
related_id = renderer.try &.["channelId"]?.try &.as_s?
|
|
|
|
if browse_id
|
|
|
|
related_id ||= ""
|
|
|
|
related_channels = RelatedChannels.new(browse_id: browse_id, params: params)
|
|
|
|
|
|
|
|
|
|
|
|
related_title = renderer.try &.["title"]?.try &.["simpleText"]?.try &.as_s?
|
|
|
|
|
|
|
|
related_title ||= ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
related_author_url = renderer.try &.["navigationEndpoint"]?.try &.["commandMetadata"]?.try &.["webCommandMetadata"]?
|
|
|
|
|
|
|
|
.try &.["url"]?.try &.as_s?
|
|
|
|
|
|
|
|
related_author_url ||= ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
related_author_thumbnails = renderer.try &.["thumbnail"]?.try &.["thumbnails"]?.try &.as_a?
|
|
|
|
|
|
|
|
related_author_thumbnails ||= [] of JSON::Any
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
related_author_thumbnail = ""
|
|
|
|
|
|
|
|
if related_author_thumbnails.size > 0
|
|
|
|
|
|
|
|
related_author_thumbnail = related_author_thumbnails[-1]["url"]?.try &.as_s?
|
|
|
|
|
|
|
|
related_author_thumbnail ||= ""
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
AboutRelatedChannel.new({
|
|
|
|
|
|
|
|
ucid: related_id,
|
|
|
|
|
|
|
|
author: related_title,
|
|
|
|
|
|
|
|
author_url: related_author_url,
|
|
|
|
|
|
|
|
author_thumbnail: related_author_thumbnail,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
related_channels ||= [] of AboutRelatedChannel
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
total_views = 0_i64
|
|
|
|
total_views = 0_i64
|
|
|
@ -155,7 +129,7 @@ def get_about_info(ucid, locale)
|
|
|
|
sub_count = initdata["header"]["c4TabbedHeaderRenderer"]?.try &.["subscriberCountText"]?.try &.["simpleText"]?.try &.as_s?
|
|
|
|
sub_count = initdata["header"]["c4TabbedHeaderRenderer"]?.try &.["subscriberCountText"]?.try &.["simpleText"]?.try &.as_s?
|
|
|
|
.try { |text| short_text_to_number(text.split(" ")[0]) } || 0
|
|
|
|
.try { |text| short_text_to_number(text.split(" ")[0]) } || 0
|
|
|
|
|
|
|
|
|
|
|
|
AboutChannel.new({
|
|
|
|
AboutChannel.new(
|
|
|
|
ucid: ucid,
|
|
|
|
ucid: ucid,
|
|
|
|
author: author,
|
|
|
|
author: author,
|
|
|
|
auto_generated: auto_generated,
|
|
|
|
auto_generated: auto_generated,
|
|
|
@ -170,5 +144,29 @@ def get_about_info(ucid, locale)
|
|
|
|
allowed_regions: allowed_regions,
|
|
|
|
allowed_regions: allowed_regions,
|
|
|
|
related_channels: related_channels,
|
|
|
|
related_channels: related_channels,
|
|
|
|
tabs: tabs,
|
|
|
|
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 || "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tabs = channels.dig?("contents", "twoColumnBrowseResultsRenderer", "tabs").try(&.as_a?) || [] of JSON::Any
|
|
|
|
|
|
|
|
tab = tabs.find { |tab| tab.dig?("tabRenderer", "title").try(&.as_s?) == "Channels" }
|
|
|
|
|
|
|
|
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(
|
|
|
|
|
|
|
|
ucid: related_id,
|
|
|
|
|
|
|
|
author: related_title,
|
|
|
|
|
|
|
|
author_url: related_author_url,
|
|
|
|
|
|
|
|
author_thumbnail: related_author_thumbnail,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|