Change AboutChannel tabs to hash of name and param

This is to help fetch tab contents from the browse endpoint of youtube
later on.
This commit is contained in:
syeopite 2021-04-17 04:33:19 -07:00
parent 4d1297f257
commit a777eda66a
No known key found for this signature in database
GPG Key ID: 6FA616E5A5294A82
3 changed files with 7 additions and 5 deletions

View File

@ -135,7 +135,7 @@ struct AboutChannel
property is_family_friendly : Bool
property allowed_regions : Array(String)
property related_channels : Array(AboutRelatedChannel)
property tabs : Array(String)
property tabs : Hash(String, String)
property links : Array(Tuple(String, String, String))
end
@ -887,7 +887,7 @@ def get_about_info(ucid, locale)
country = ""
total_views = 0_i64
joined = Time.unix(0)
tabs = [] of String
tabs = {} of String => String # TabName => browseEndpoint params
links = [] of {String, String, String}
tabs_json = initdata["contents"]["twoColumnBrowseResultsRenderer"]["tabs"]?.try &.as_a?
@ -936,7 +936,9 @@ def get_about_info(ucid, locale)
end
end
end
tabs = tabs_json.reject { |node| node["tabRenderer"]?.nil? }.map { |node| node["tabRenderer"]["title"].as_s.downcase }
tab_names = tabs_json.reject { |node| node["tabRenderer"]?.nil? }.map { |node| node["tabRenderer"]["title"].as_s.downcase }
browse_endpoint_param = tabs_json.reject { |node| node["tabRenderer"]?.nil? }.map { |node| node["tabRenderer"]["endpoint"]["browseEndpoint"]["params"].as_s }
tabs = Hash.zip(tab_names, browse_endpoint_param)
end
sub_count = initdata["header"]["c4TabbedHeaderRenderer"]?.try &.["subscriberCountText"]?.try &.["simpleText"]?.try &.as_s?

View File

@ -75,7 +75,7 @@ class Invidious::Routes::Channels < Invidious::Routes::BaseRoute
continuation = env.params.query["continuation"]?
# sort_by = env.params.query["sort_by"]?.try &.downcase
if !channel.tabs.includes? "community"
if !channel.tabs.has_key?("community")
return env.redirect "/channel/#{channel.ucid}"
end

View File

@ -90,7 +90,7 @@
</li>
<% end %>
<% if channel.tabs.includes? "community" %>
<% if channel.tabs.has_key?("community") %>
<% if content_type == 2 %>
<li class="pure-menu-item pure-menu-selected">
<a class="pure-menu-link" href="/channel/<%= channel.ucid %>/community">