Replace channel tab param fetch with hardcoded ones

This commit is contained in:
syeopite 2021-06-24 18:12:07 -07:00
parent 462ef800ff
commit 746ce6b71c
No known key found for this signature in database
GPG Key ID: 6FA616E5A5294A82
3 changed files with 14 additions and 42 deletions

View File

@ -135,7 +135,7 @@ struct AboutChannel
property is_family_friendly : Bool property is_family_friendly : Bool
property allowed_regions : Array(String) property allowed_regions : Array(String)
property related_channels : Array(AboutRelatedChannel) property related_channels : Array(AboutRelatedChannel)
property tabs : Hash(String, Tuple(Int32, String)) # TabName => {TabiZZndex, browseEndpoint params} property tabs : Array(String)
property links : Array(Tuple(String, String, String)) property links : Array(Tuple(String, String, String))
end end
@ -342,7 +342,7 @@ def fetch_channel(ucid, db, pull_all_videos = true, locale = nil)
end end
def fetch_channel_home(ucid, channel) def fetch_channel_home(ucid, channel)
initial_data = request_youtube_api_browse(ucid, channel.tabs["home"][1]) initial_data = request_youtube_api_browse(ucid, "EghmZWF0dXJlZA%3D%3D")
items = extract_items(initial_data, channel.author, channel.ucid) items = extract_items(initial_data, channel.author, channel.ucid)
# Channel trailer needs some slight special handling # Channel trailer needs some slight special handling
@ -403,7 +403,7 @@ def fetch_channel_playlists(ucid, author, continuation, sort_by)
return items, continuation return items, continuation
end end
def fetch_channel_featured_channels(ucid, tab_data, view = nil, shelf_id = nil, continuation = nil, query_title = nil) : {Array(Category), (String | Nil)} def fetch_channel_featured_channels(ucid, params, view = nil, shelf_id = nil, continuation = nil, query_title = nil) : {Array(Category), (String | Nil)}
if continuation.is_a?(String) if continuation.is_a?(String)
initial_data = request_youtube_api_browse(continuation) initial_data = request_youtube_api_browse(continuation)
items = extract_items(initial_data) items = extract_items(initial_data)
@ -425,7 +425,7 @@ def fetch_channel_featured_channels(ucid, tab_data, view = nil, shelf_id = nil,
initial_data = request_youtube_api_browse(ucid, params) initial_data = request_youtube_api_browse(ucid, params)
continuation_token = fetch_continuation_token(initial_data) continuation_token = fetch_continuation_token(initial_data)
else else
initial_data = request_youtube_api_browse(ucid, tab_data[1]) initial_data = request_youtube_api_browse(ucid, params)
continuation_token = nil continuation_token = nil
end end
@ -1000,16 +1000,14 @@ def get_about_info(ucid, locale)
country = "" country = ""
total_views = 0_i64 total_views = 0_i64
joined = Time.unix(0) joined = Time.unix(0)
tabs = {} of String => Tuple(Int32, String) # TabName => {TabiZZndex, browseEndpoint params}
links = [] of {String, String, String} links = [] of {String, String, String}
tabs_json = initdata["contents"]["twoColumnBrowseResultsRenderer"]["tabs"]?.try &.as_a? tabs = [] of String
tab_names = [] of String
tab_data = [] of Tuple(Int32, String)
tabs_json = initdata["contents"]["twoColumnBrowseResultsRenderer"]["tabs"]?.try &.as_a?
if !tabs_json.nil? if !tabs_json.nil?
# Retrieve information from the tabs array. The index we are looking for varies between channels. # Retrieve information from the tabs array. The index we are looking for varies between channels.
tabs_json.each_with_index do |node, i| tabs_json.each do |node|
# Try to find the about section which is located in only one of the tabs. # Try to find the about section which is located in only one of the tabs.
channel_about_meta = node["tabRenderer"]?.try &.["content"]?.try &.["sectionListRenderer"]? channel_about_meta = node["tabRenderer"]?.try &.["content"]?.try &.["sectionListRenderer"]?
.try &.["contents"]?.try &.[0]?.try &.["itemSectionRenderer"]?.try &.["contents"]? .try &.["contents"]?.try &.[0]?.try &.["itemSectionRenderer"]?.try &.["contents"]?
@ -1022,27 +1020,6 @@ 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)
# External link parsing
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)
link_icon_url = link["icon"]?.try &.["thumbnails"][0]["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, link_icon_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"]
@ -1051,13 +1028,8 @@ def get_about_info(ucid, locale)
auto_generated = true auto_generated = true
end end
end end
if node["tabRenderer"]?
tab_names << node["tabRenderer"]["title"].as_s.downcase
tab_data << {i, node["tabRenderer"]["endpoint"]["browseEndpoint"]["params"].as_s}
end
end end
tabs = Hash.zip(tab_names, tab_data) tabs = tabs_json.reject { |node| node["tabRenderer"]?.nil? }.map { |node| node["tabRenderer"]["title"].as_s.downcase }
end end
sub_count = initdata["header"]["c4TabbedHeaderRenderer"]?.try &.["subscriberCountText"]?.try &.["simpleText"]?.try &.as_s? sub_count = initdata["header"]["c4TabbedHeaderRenderer"]?.try &.["subscriberCountText"]?.try &.["simpleText"]?.try &.as_s?

View File

@ -87,7 +87,7 @@ class Invidious::Routes::Channels < Invidious::Routes::BaseRoute
continuation = env.params.query["continuation"]? continuation = env.params.query["continuation"]?
# sort_by = env.params.query["sort_by"]?.try &.downcase # sort_by = env.params.query["sort_by"]?.try &.downcase
if !channel.tabs.has_key?("community") if !channel.tabs.includes?("community")
return env.redirect "/channel/#{channel.ucid}" return env.redirect "/channel/#{channel.ucid}"
end end
@ -110,7 +110,7 @@ class Invidious::Routes::Channels < Invidious::Routes::BaseRoute
end end
locale, user, subscriptions, continuation, ucid, channel = data locale, user, subscriptions, continuation, ucid, channel = data
if !channel.tabs.has_key?("channels") if !channel.tabs.includes?("channels")
return env.redirect "/channel/#{channel.ucid}" return env.redirect "/channel/#{channel.ucid}"
end end
@ -131,7 +131,7 @@ class Invidious::Routes::Channels < Invidious::Routes::BaseRoute
# Previous continuation # Previous continuation
previous_continuation = env.params.query["previous"]? previous_continuation = env.params.query["previous"]?
featured_channel_categories, continuation_token = fetch_channel_featured_channels(ucid, channel.tabs["channels"], nil, nil, continuation, current_category_title).not_nil! featured_channel_categories, continuation_token = fetch_channel_featured_channels(ucid, "EghjaGFubmVscw%3D%3D", nil, nil, continuation, current_category_title).not_nil!
elsif view && shelf_id elsif view && shelf_id
offset = env.params.query["offset"]? offset = env.params.query["offset"]?
if offset if offset
@ -140,12 +140,12 @@ class Invidious::Routes::Channels < Invidious::Routes::BaseRoute
offset = 0 offset = 0
end end
featured_channel_categories, continuation_token = fetch_channel_featured_channels(ucid, channel.tabs["channels"], view, shelf_id, continuation, current_category_title).not_nil! featured_channel_categories, continuation_token = fetch_channel_featured_channels(ucid, "EghjaGFubmVscw%3D%3D", view, shelf_id, continuation, current_category_title).not_nil!
else else
previous_continuation = nil previous_continuation = nil
offset = 0 offset = 0
featured_channel_categories, continuation_token = fetch_channel_featured_channels(ucid, channel.tabs["channels"], nil, nil, current_category_title).not_nil! featured_channel_categories, continuation_token = fetch_channel_featured_channels(ucid, "EghjaGFubmVscw%3D%3D", nil, nil, current_category_title).not_nil!
end end
templated "channel/featured_channels", buffer_footer: true templated "channel/featured_channels", buffer_footer: true

View File

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