mirror of
https://github.com/iv-org/invidious.git
synced 2025-07-28 16:28:29 +00:00
Fix: Search not showing next page button when a next page exists
This commit is contained in:
parent
2414e7db41
commit
4627dbbe1c
@ -440,7 +440,7 @@ module Invidious::Routes::API::V1::Channels
|
|||||||
query.channel = env.params.url["ucid"]
|
query.channel = env.params.url["ucid"]
|
||||||
|
|
||||||
begin
|
begin
|
||||||
search_results = query.process
|
search_results, _ = query.process
|
||||||
rescue ex
|
rescue ex
|
||||||
return error_json(400, ex)
|
return error_json(400, ex)
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,7 @@ module Invidious::Routes::API::V1::Search
|
|||||||
query = Invidious::Search::Query.new(env.params.query, :regular, region)
|
query = Invidious::Search::Query.new(env.params.query, :regular, region)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
search_results = query.process
|
search_results, _ = query.process
|
||||||
rescue ex
|
rescue ex
|
||||||
return error_json(400, ex)
|
return error_json(400, ex)
|
||||||
end
|
end
|
||||||
|
@ -254,9 +254,11 @@ module Invidious::Routes::Playlists
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
query = Invidious::Search::Query.new(env.params.query, :playlist, region)
|
query = Invidious::Search::Query.new(env.params.query, :playlist, region)
|
||||||
items = query.process.select(SearchVideo).map(&.as(SearchVideo))
|
processed_query, has_continuation = query.process
|
||||||
|
items = processed_query.select(SearchVideo).map(&.as(SearchVideo))
|
||||||
rescue ex
|
rescue ex
|
||||||
items = [] of SearchVideo
|
items = [] of SearchVideo
|
||||||
|
has_continuation = false
|
||||||
end
|
end
|
||||||
|
|
||||||
# Pagination
|
# Pagination
|
||||||
@ -264,7 +266,7 @@ module Invidious::Routes::Playlists
|
|||||||
page_nav_html = Frontend::Pagination.nav_numeric(locale,
|
page_nav_html = Frontend::Pagination.nav_numeric(locale,
|
||||||
base_url: "/add_playlist_items?list=#{playlist.id}&q=#{query_encoded}",
|
base_url: "/add_playlist_items?list=#{playlist.id}&q=#{query_encoded}",
|
||||||
current_page: page,
|
current_page: page,
|
||||||
show_next: (items.size >= 20)
|
show_next: has_continuation
|
||||||
)
|
)
|
||||||
|
|
||||||
env.set "add_playlist_items", plid
|
env.set "add_playlist_items", plid
|
||||||
|
@ -52,7 +52,7 @@ module Invidious::Routes::Search
|
|||||||
user = env.get? "user"
|
user = env.get? "user"
|
||||||
|
|
||||||
begin
|
begin
|
||||||
items = query.process
|
items, has_continuation = query.process
|
||||||
rescue ex : ChannelSearchException
|
rescue ex : ChannelSearchException
|
||||||
return error_template(404, "Unable to find channel with id of '#{HTML.escape(ex.channel)}'. Are you sure that's an actual channel id? It should look like 'UC4QobU6STFB0P71PMvOGN5A'.")
|
return error_template(404, "Unable to find channel with id of '#{HTML.escape(ex.channel)}'. Are you sure that's an actual channel id? It should look like 'UC4QobU6STFB0P71PMvOGN5A'.")
|
||||||
rescue ex
|
rescue ex
|
||||||
@ -65,7 +65,7 @@ module Invidious::Routes::Search
|
|||||||
page_nav_html = Frontend::Pagination.nav_numeric(locale,
|
page_nav_html = Frontend::Pagination.nav_numeric(locale,
|
||||||
base_url: "/search?#{query.to_http_params}",
|
base_url: "/search?#{query.to_http_params}",
|
||||||
current_page: query.page,
|
current_page: query.page,
|
||||||
show_next: (items.size >= 20)
|
show_next: has_continuation
|
||||||
)
|
)
|
||||||
|
|
||||||
if query.type == Invidious::Search::Query::Type::Channel
|
if query.type == Invidious::Search::Query::Type::Channel
|
||||||
|
@ -3,19 +3,19 @@ module Invidious::Search
|
|||||||
extend self
|
extend self
|
||||||
|
|
||||||
# Regular search (`/search` endpoint)
|
# Regular search (`/search` endpoint)
|
||||||
def regular(query : Query) : Array(SearchItem)
|
def regular(query : Query) : {Array(SearchItem), Bool}
|
||||||
search_params = query.filters.to_yt_params(page: query.page)
|
search_params = query.filters.to_yt_params(page: query.page)
|
||||||
|
|
||||||
client_config = YoutubeAPI::ClientConfig.new(region: query.region)
|
client_config = YoutubeAPI::ClientConfig.new(region: query.region)
|
||||||
initial_data = YoutubeAPI.search(query.text, search_params, client_config: client_config)
|
initial_data = YoutubeAPI.search(query.text, search_params, client_config: client_config)
|
||||||
|
|
||||||
items, _ = extract_items(initial_data)
|
items, next_continuation = extract_items(initial_data)
|
||||||
return items.reject!(Category)
|
return items.reject!(Category), next_continuation != nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Search a youtube channel
|
# Search a youtube channel
|
||||||
# TODO: clean code, and rely more on YoutubeAPI
|
# TODO: clean code, and rely more on YoutubeAPI
|
||||||
def channel(query : Query) : Array(SearchItem)
|
def channel(query : Query) : {Array(SearchItem), Bool}
|
||||||
response = YT_POOL.client &.get("/channel/#{query.channel}")
|
response = YT_POOL.client &.get("/channel/#{query.channel}")
|
||||||
|
|
||||||
if response.status_code == 404
|
if response.status_code == 404
|
||||||
@ -31,8 +31,8 @@ module Invidious::Search
|
|||||||
continuation = produce_channel_search_continuation(ucid, query.text, query.page)
|
continuation = produce_channel_search_continuation(ucid, query.text, query.page)
|
||||||
response_json = YoutubeAPI.browse(continuation)
|
response_json = YoutubeAPI.browse(continuation)
|
||||||
|
|
||||||
items, _ = extract_items(response_json, "", ucid)
|
items, next_continuation = extract_items(response_json, "", ucid)
|
||||||
return items.reject!(Category)
|
return items.reject!(Category), next_continuation != nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Search inside of user subscriptions
|
# Search inside of user subscriptions
|
||||||
|
@ -105,26 +105,28 @@ module Invidious::Search
|
|||||||
|
|
||||||
# Run the search query using the corresponding search processor.
|
# Run the search query using the corresponding search processor.
|
||||||
# Returns either the results or an empty array of `SearchItem`.
|
# Returns either the results or an empty array of `SearchItem`.
|
||||||
def process(user : Invidious::User? = nil) : Array(SearchItem) | Array(ChannelVideo)
|
def process(user : Invidious::User? = nil) : {Array(SearchItem) | Array(ChannelVideo), Bool}
|
||||||
items = [] of SearchItem
|
items = [] of SearchItem
|
||||||
|
|
||||||
|
has_continuation = false
|
||||||
# Don't bother going further if search query is empty
|
# Don't bother going further if search query is empty
|
||||||
return items if self.empty_raw_query?
|
return items, has_continuation if self.empty_raw_query?
|
||||||
|
|
||||||
case @type
|
case @type
|
||||||
when .regular?, .playlist?
|
when .regular?, .playlist?
|
||||||
items = Processors.regular(self)
|
items, has_continuation = Processors.regular(self)
|
||||||
#
|
#
|
||||||
when .channel?
|
when .channel?
|
||||||
items = Processors.channel(self)
|
items, has_continuation = Processors.channel(self)
|
||||||
#
|
#
|
||||||
when .subscriptions?
|
when .subscriptions?
|
||||||
if user
|
if user
|
||||||
items = Processors.subscriptions(self, user.as(Invidious::User))
|
items = Processors.subscriptions(self, user.as(Invidious::User))
|
||||||
|
has_continuation = items.size >= 20
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return items
|
return items, has_continuation
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return the HTTP::Params corresponding to this Query (invidious format)
|
# Return the HTTP::Params corresponding to this Query (invidious format)
|
||||||
|
@ -720,8 +720,11 @@ private module Extractors
|
|||||||
raw_items = [] of Array(JSON::Any)
|
raw_items = [] of Array(JSON::Any)
|
||||||
|
|
||||||
target.dig("primaryContents", "sectionListRenderer", "contents").as_a.each do |node|
|
target.dig("primaryContents", "sectionListRenderer", "contents").as_a.each do |node|
|
||||||
if node = node["itemSectionRenderer"]?
|
if new_node = node["itemSectionRenderer"]?
|
||||||
raw_items << node["contents"].as_a
|
raw_items << new_node["contents"].as_a
|
||||||
|
end
|
||||||
|
if node["continuationItemRenderer"]?
|
||||||
|
raw_items.push([node])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user