mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-03-16.git
synced 2024-08-15 00:53:18 +00:00
Move continuation_token out of Category struct
This commit is contained in:
parent
cc02fed4e6
commit
0e96eda28f
6 changed files with 20 additions and 26 deletions
|
@ -380,8 +380,8 @@ 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)
|
def fetch_channel_featured_channels(ucid, tab_data, view = nil, shelf_id = nil, continuation = nil, query_title = nil) : {Array(Category), (String|Nil)}
|
||||||
auxiliary_data = {} of String => String
|
auxiliary_data = {} of String => String
|
||||||
|
|
||||||
if continuation.is_a?(String)
|
if continuation.is_a?(String)
|
||||||
initial_data = request_youtube_api_browse(continuation)
|
initial_data = request_youtube_api_browse(continuation)
|
||||||
|
@ -392,10 +392,9 @@ def fetch_channel_featured_channels(ucid, tab_data, view=nil, shelf_id=nil, cont
|
||||||
title: query_title.not_nil!, # If continuation contents is requested then the query_title has to be passed along.
|
title: query_title.not_nil!, # If continuation contents is requested then the query_title has to be passed along.
|
||||||
contents: items,
|
contents: items,
|
||||||
browse_endpoint_data: nil,
|
browse_endpoint_data: nil,
|
||||||
continuation_token: continuation_token,
|
|
||||||
badges: nil,
|
badges: nil,
|
||||||
auxiliary_data: auxiliary_data,
|
auxiliary_data: auxiliary_data,
|
||||||
})]
|
})], continuation_token
|
||||||
else
|
else
|
||||||
if view && shelf_id
|
if view && shelf_id
|
||||||
auxiliary_data["view"] = view
|
auxiliary_data["view"] = view
|
||||||
|
@ -414,11 +413,11 @@ def fetch_channel_featured_channels(ucid, tab_data, view=nil, shelf_id=nil, cont
|
||||||
|
|
||||||
# There's no submenu data if the channel doesn't feature any channels.
|
# There's no submenu data if the channel doesn't feature any channels.
|
||||||
if !submenu
|
if !submenu
|
||||||
return [] of Category
|
return {[] of Category, continuation_token}
|
||||||
end
|
end
|
||||||
|
|
||||||
submenu_data = submenu["channelSubMenuRenderer"]["contentTypeSubMenuItems"]
|
submenu_data = submenu["channelSubMenuRenderer"]["contentTypeSubMenuItems"]
|
||||||
|
|
||||||
items = extract_items(initial_data)
|
items = extract_items(initial_data)
|
||||||
fallback_title = submenu_data.as_a.select(&.["selected"].as_bool)[0]["title"].as_s
|
fallback_title = submenu_data.as_a.select(&.["selected"].as_bool)[0]["title"].as_s
|
||||||
|
|
||||||
|
@ -436,8 +435,7 @@ def fetch_channel_featured_channels(ucid, tab_data, view=nil, shelf_id=nil, cont
|
||||||
category_array << Category.new({
|
category_array << Category.new({
|
||||||
title: category.title.empty? ? fallback_title : category.title,
|
title: category.title.empty? ? fallback_title : category.title,
|
||||||
contents: category.contents,
|
contents: category.contents,
|
||||||
browse_endpoint_data: category.browse_endpoint_data,
|
browse_endpoint_data: nil,
|
||||||
continuation_token: continuation_token,
|
|
||||||
badges: nil,
|
badges: nil,
|
||||||
auxiliary_data: category.auxiliary_data,
|
auxiliary_data: category.auxiliary_data,
|
||||||
})
|
})
|
||||||
|
@ -445,25 +443,24 @@ def fetch_channel_featured_channels(ucid, tab_data, view=nil, shelf_id=nil, cont
|
||||||
|
|
||||||
# If we don't have any categories we'll create one.
|
# If we don't have any categories we'll create one.
|
||||||
if category_array.empty?
|
if category_array.empty?
|
||||||
return [Category.new({
|
category_array << Category.new({
|
||||||
title: fallback_title,
|
title: fallback_title,
|
||||||
contents: items,
|
contents: items,
|
||||||
browse_endpoint_data: nil,
|
browse_endpoint_data: nil,
|
||||||
continuation_token: continuation_token,
|
|
||||||
badges: nil,
|
badges: nil,
|
||||||
auxiliary_data: auxiliary_data,
|
auxiliary_data: auxiliary_data,
|
||||||
})]
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
return category_array
|
return category_array, continuation_token
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def produce_featured_channel_browse_param(view : Int64, shelf_id : Int64)
|
def produce_featured_channel_browse_param(view : Int64, shelf_id : Int64)
|
||||||
object = {
|
object = {
|
||||||
"2:string" => "channels",
|
"2:string" => "channels",
|
||||||
"4:varint" => view,
|
"4:varint" => view,
|
||||||
"14:varint" => shelf_id
|
"14:varint" => shelf_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
browse_params = object.try { |i| Protodec::Any.cast_json(object) }
|
browse_params = object.try { |i| Protodec::Any.cast_json(object) }
|
||||||
|
|
|
@ -219,7 +219,7 @@ private class CategoryParser < ItemParser
|
||||||
title = ""
|
title = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
auxiliary_data = {} of String => String
|
auxiliary_data = {} of String => String
|
||||||
browse_endpoint = item_contents["endpoint"]?.try &.["browseEndpoint"] || nil
|
browse_endpoint = item_contents["endpoint"]?.try &.["browseEndpoint"] || nil
|
||||||
browse_endpoint_data = ""
|
browse_endpoint_data = ""
|
||||||
category_type = 0 # 0: Video, 1: Channels, 2: Playlist/feed, 3: trending
|
category_type = 0 # 0: Video, 1: Channels, 2: Playlist/feed, 3: trending
|
||||||
|
@ -243,7 +243,7 @@ private class CategoryParser < ItemParser
|
||||||
url = URI.parse(url.as_s)
|
url = URI.parse(url.as_s)
|
||||||
auxiliary_data["view"] = url.query_params["view"]
|
auxiliary_data["view"] = url.query_params["view"]
|
||||||
auxiliary_data["shelf_id"] = url.query_params["shelf_id"]
|
auxiliary_data["shelf_id"] = url.query_params["shelf_id"]
|
||||||
|
|
||||||
category_type = 1
|
category_type = 1
|
||||||
else
|
else
|
||||||
browse_endpoint_data = browse_endpoint["browseId"].as_s
|
browse_endpoint_data = browse_endpoint["browseId"].as_s
|
||||||
|
@ -281,7 +281,6 @@ private class CategoryParser < ItemParser
|
||||||
title: title,
|
title: title,
|
||||||
contents: contents,
|
contents: contents,
|
||||||
browse_endpoint_data: browse_endpoint_data,
|
browse_endpoint_data: browse_endpoint_data,
|
||||||
continuation_token: nil,
|
|
||||||
badges: badges,
|
badges: badges,
|
||||||
auxiliary_data: auxiliary_data,
|
auxiliary_data: auxiliary_data,
|
||||||
})
|
})
|
||||||
|
@ -413,7 +412,7 @@ def extract_items(initial_data : Hash(String, JSON::Any), author_fallback : Stri
|
||||||
items << parsed_result
|
items << parsed_result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return items
|
return items
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -266,8 +266,7 @@ end
|
||||||
def fetch_continuation_token(items : Array(JSON::Any))
|
def fetch_continuation_token(items : Array(JSON::Any))
|
||||||
# Fetches the continuation token from an array of items
|
# Fetches the continuation token from an array of items
|
||||||
return items.last["continuationItemRenderer"]?
|
return items.last["continuationItemRenderer"]?
|
||||||
.try &.["continuationEndpoint"]["continuationCommand"]["token"].as_s
|
.try &.["continuationEndpoint"]["continuationCommand"]["token"].as_s
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_continuation_token(initial_data : Hash(String, JSON::Any))
|
def fetch_continuation_token(initial_data : Hash(String, JSON::Any))
|
||||||
|
|
|
@ -234,7 +234,6 @@ class Category
|
||||||
property title : String
|
property title : String
|
||||||
property contents : Array(SearchItem) | SearchItem
|
property contents : Array(SearchItem) | SearchItem
|
||||||
property browse_endpoint_data : String?
|
property browse_endpoint_data : String?
|
||||||
property continuation_token : String?
|
|
||||||
property badges : Array(Tuple(String, String))?
|
property badges : Array(Tuple(String, String))?
|
||||||
|
|
||||||
# Data unique to only specific types of categories.
|
# Data unique to only specific types of categories.
|
||||||
|
|
|
@ -119,7 +119,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 = 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, channel.tabs["channels"], 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
|
||||||
|
@ -128,12 +128,12 @@ class Invidious::Routes::Channels < Invidious::Routes::BaseRoute
|
||||||
offset = 0
|
offset = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
featured_channel_categories = 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, channel.tabs["channels"], view, shelf_id, continuation, current_category_title).not_nil!
|
||||||
else
|
else
|
||||||
previous_continuation = nil
|
previous_continuation = nil
|
||||||
offset = 0
|
offset = 0
|
||||||
|
|
||||||
featured_channel_categories = 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, channel.tabs["channels"], nil, nil, current_category_title).not_nil!
|
||||||
end
|
end
|
||||||
|
|
||||||
templated "channel/featured_channels", buffer_footer: true
|
templated "channel/featured_channels", buffer_footer: true
|
||||||
|
|
|
@ -106,7 +106,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="pure-u-1 pure-u-lg-3-5"></div>
|
<div class="pure-u-1 pure-u-lg-3-5"></div>
|
||||||
<div class="pure-u-1 pure-u-lg-1-5" style="text-align:right">
|
<div class="pure-u-1 pure-u-lg-1-5" style="text-align:right">
|
||||||
<% if (next_cont_token = featured_channel_categories[0].continuation_token) %>
|
<% if (next_cont_token = continuation_token) %>
|
||||||
<% previous = ""%>
|
<% previous = ""%>
|
||||||
<% if continuation %>
|
<% if continuation %>
|
||||||
<% previous = "&previous=#{HTML.escape(continuation)}"%>
|
<% previous = "&previous=#{HTML.escape(continuation)}"%>
|
||||||
|
|
Loading…
Reference in a new issue