From a777eda66a75ae348d84da542602df15698ec2db Mon Sep 17 00:00:00 2001 From: syeopite Date: Sat, 17 Apr 2021 04:33:19 -0700 Subject: [PATCH] Change AboutChannel tabs to hash of name and param This is to help fetch tab contents from the browse endpoint of youtube later on. --- src/invidious/channels.cr | 8 +++++--- src/invidious/routes/channels.cr | 2 +- src/invidious/views/components/channel-information.ecr | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/invidious/channels.cr b/src/invidious/channels.cr index cba5577c..636d5a31 100644 --- a/src/invidious/channels.cr +++ b/src/invidious/channels.cr @@ -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? diff --git a/src/invidious/routes/channels.cr b/src/invidious/routes/channels.cr index b51ff714..7fa5a5e4 100644 --- a/src/invidious/routes/channels.cr +++ b/src/invidious/routes/channels.cr @@ -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 diff --git a/src/invidious/views/components/channel-information.ecr b/src/invidious/views/components/channel-information.ecr index 45b8dc62..501896da 100644 --- a/src/invidious/views/components/channel-information.ecr +++ b/src/invidious/views/components/channel-information.ecr @@ -90,7 +90,7 @@ <% end %> - <% if channel.tabs.includes? "community" %> + <% if channel.tabs.has_key?("community") %> <% if content_type == 2 %>