mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-03-16.git
synced 2024-08-15 00:53:18 +00:00
Add logic to parse external chan links and country
This commit is contained in:
parent
425112629d
commit
90bd19dc45
1 changed files with 26 additions and 1 deletions
|
@ -9,6 +9,7 @@ struct AboutChannel
|
||||||
property author_thumbnail : String
|
property author_thumbnail : String
|
||||||
property banner : String?
|
property banner : String?
|
||||||
property description_html : String
|
property description_html : String
|
||||||
|
property country : String
|
||||||
property total_views : Int64
|
property total_views : Int64
|
||||||
property sub_count : Int32
|
property sub_count : Int32
|
||||||
property joined : Time
|
property joined : Time
|
||||||
|
@ -16,6 +17,7 @@ struct AboutChannel
|
||||||
property allowed_regions : Array(String)
|
property allowed_regions : Array(String)
|
||||||
property related_channels : Array(AboutRelatedChannel)
|
property related_channels : Array(AboutRelatedChannel)
|
||||||
property tabs : Array(String)
|
property tabs : Array(String)
|
||||||
|
property links : Array(Tuple(String, String))
|
||||||
end
|
end
|
||||||
|
|
||||||
struct AboutRelatedChannel
|
struct AboutRelatedChannel
|
||||||
|
@ -119,10 +121,11 @@ def get_about_info(ucid, locale)
|
||||||
related_channels ||= [] of AboutRelatedChannel
|
related_channels ||= [] of AboutRelatedChannel
|
||||||
end
|
end
|
||||||
|
|
||||||
|
country = ""
|
||||||
total_views = 0_i64
|
total_views = 0_i64
|
||||||
joined = Time.unix(0)
|
joined = Time.unix(0)
|
||||||
|
|
||||||
tabs = [] of String
|
tabs = [] of String
|
||||||
|
links = [] of {String, String}
|
||||||
|
|
||||||
tabs_json = initdata["contents"]["twoColumnBrowseResultsRenderer"]["tabs"]?.try &.as_a?
|
tabs_json = initdata["contents"]["twoColumnBrowseResultsRenderer"]["tabs"]?.try &.as_a?
|
||||||
if !tabs_json.nil?
|
if !tabs_json.nil?
|
||||||
|
@ -140,6 +143,26 @@ def get_about_info(ucid, locale)
|
||||||
joined = channel_about_meta["joinedDateText"]?.try &.["runs"]?.try &.as_a.reduce("") { |acc, node| acc + node["text"].as_s }
|
joined = channel_about_meta["joinedDateText"]?.try &.["runs"]?.try &.as_a.reduce("") { |acc, node| acc + node["text"].as_s }
|
||||||
.try { |text| Time.parse(text, "Joined %b %-d, %Y", Time::Location.local) } || Time.unix(0)
|
.try { |text| Time.parse(text, "Joined %b %-d, %Y", Time::Location.local) } || Time.unix(0)
|
||||||
|
|
||||||
|
channel_about_meta["primaryLinks"]?.try &.as_a.each do |link|
|
||||||
|
link_title = link["title"]["simpleText"].as_s
|
||||||
|
link_url = URI.parse(link["navigationEndpoint"]["urlEndpoint"]["url"].to_s)
|
||||||
|
|
||||||
|
if {"m.youtube.com", "www.youtube.com", "youtu.be"}.includes? link_url.host
|
||||||
|
if link_url.path == "/redirect"
|
||||||
|
link_url = HTTP::Params.parse(link_url.query.not_nil!)["q"]
|
||||||
|
else
|
||||||
|
link_url = link_url.request_target.to_s
|
||||||
|
end
|
||||||
|
else
|
||||||
|
link_url = link_url.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
links << {link_title, link_url}
|
||||||
|
end
|
||||||
|
|
||||||
|
country = channel_about_meta["country"]?.try &.["simpleText"].as_s || ""
|
||||||
|
|
||||||
|
|
||||||
# Normal Auto-generated channels
|
# Normal Auto-generated channels
|
||||||
# https://support.google.com/youtube/answer/2579942
|
# https://support.google.com/youtube/answer/2579942
|
||||||
# For auto-generated channels, channel_about_meta only has ["description"]["simpleText"] and ["primaryLinks"][0]["title"]["simpleText"]
|
# For auto-generated channels, channel_about_meta only has ["description"]["simpleText"] and ["primaryLinks"][0]["title"]["simpleText"]
|
||||||
|
@ -163,6 +186,7 @@ def get_about_info(ucid, locale)
|
||||||
author_thumbnail: author_thumbnail,
|
author_thumbnail: author_thumbnail,
|
||||||
banner: banner,
|
banner: banner,
|
||||||
description_html: description_html,
|
description_html: description_html,
|
||||||
|
country: country,
|
||||||
total_views: total_views,
|
total_views: total_views,
|
||||||
sub_count: sub_count,
|
sub_count: sub_count,
|
||||||
joined: joined,
|
joined: joined,
|
||||||
|
@ -170,5 +194,6 @@ 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,
|
||||||
|
links: links
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue