diff --git a/src/invidious/routes/api/v1/channels.cr b/src/invidious/routes/api/v1/channels.cr index 322ac42e..3e55b412 100644 --- a/src/invidious/routes/api/v1/channels.cr +++ b/src/invidious/routes/api/v1/channels.cr @@ -254,7 +254,7 @@ module Invidious::Routes::API::V1::Channels page = env.params.query["page"]?.try &.to_i? page ||= 1 - count, search_results = channel_search(query, page, ucid) + search_results = channel_search(query, page, ucid) JSON.build do |json| json.array do search_results.each do |item| diff --git a/src/invidious/routes/api/v1/search.cr b/src/invidious/routes/api/v1/search.cr index a3b6c795..0b0853b1 100644 --- a/src/invidious/routes/api/v1/search.cr +++ b/src/invidious/routes/api/v1/search.cr @@ -32,7 +32,7 @@ module Invidious::Routes::API::V1::Search return error_json(400, ex) end - count, search_results = search(query, search_params, region).as(Tuple) + search_results = search(query, search_params, region) JSON.build do |json| json.array do search_results.each do |item| diff --git a/src/invidious/routes/playlists.cr b/src/invidious/routes/playlists.cr index 7a502a05..9c73874e 100644 --- a/src/invidious/routes/playlists.cr +++ b/src/invidious/routes/playlists.cr @@ -247,15 +247,13 @@ module Invidious::Routes::Playlists query = env.params.query["q"]? if query begin - search_query, count, items, operators = process_search_query(query, page, user, region: nil) + search_query, items, operators = process_search_query(query, page, user, region: nil) videos = items.select(SearchVideo).map(&.as(SearchVideo)) rescue ex videos = [] of SearchVideo - count = 0 end else videos = [] of SearchVideo - count = 0 end env.set "add_playlist_items", plid diff --git a/src/invidious/routes/search.cr b/src/invidious/routes/search.cr index 5e606adf..3f4c7e5e 100644 --- a/src/invidious/routes/search.cr +++ b/src/invidious/routes/search.cr @@ -54,7 +54,7 @@ module Invidious::Routes::Search user = env.get? "user" begin - search_query, count, videos, operators = process_search_query(query, page, user, region: region) + search_query, videos, operators = process_search_query(query, page, user, region: region) 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'.") rescue ex diff --git a/src/invidious/search.cr b/src/invidious/search.cr index 0f6dc6eb..45d29059 100644 --- a/src/invidious/search.cr +++ b/src/invidious/search.cr @@ -5,7 +5,7 @@ class ChannelSearchException < InfoException end end -def channel_search(query, page, channel) +def channel_search(query, page, channel) : Array(SearchItem) response = YT_POOL.client &.get("/channel/#{channel}") if response.status_code == 404 @@ -24,7 +24,7 @@ def channel_search(query, page, channel) continuation_items = response_json["onResponseReceivedActions"]? .try &.[0]["appendContinuationItemsAction"]["continuationItems"] - return 0, [] of SearchItem if !continuation_items + return [] of SearchItem if !continuation_items items = [] of SearchItem continuation_items.as_a.select(&.as_h.has_key?("itemSectionRenderer")).each { |item| @@ -32,17 +32,16 @@ def channel_search(query, page, channel) .try { |t| items << t } } - return items.size, items + return items end -def search(query, search_params = produce_search_params(content_type: "all"), region = nil) - return 0, [] of SearchItem if query.empty? +def search(query, search_params = produce_search_params(content_type: "all"), region = nil) : Array(SearchItem) + return [] of SearchItem if query.empty? client_config = YoutubeAPI::ClientConfig.new(region: region) initial_data = YoutubeAPI.search(query, search_params, client_config: client_config) - items = extract_items(initial_data) - return items.size, items + return extract_items(initial_data) end def produce_search_params(page = 1, sort : String = "relevance", date : String = "", content_type : String = "", @@ -217,7 +216,7 @@ def process_search_query(query, page, user, region) search_query = (query.split(" ") - operators).join(" ") if channel - count, items = channel_search(search_query, page, channel) + items = channel_search(search_query, page, channel) elsif subscriptions if view_name items = PG_DB.query_all("SELECT id,title,published,updated,ucid,author,length_seconds FROM ( @@ -227,16 +226,14 @@ def process_search_query(query, page, user, region) as document FROM #{view_name} ) v_search WHERE v_search.document @@ plainto_tsquery($1) LIMIT 20 OFFSET $2;", search_query, (page - 1) * 20, as: ChannelVideo) - count = items.size else items = [] of ChannelVideo - count = 0 end else search_params = produce_search_params(page: page, sort: sort, date: date, content_type: content_type, duration: duration, features: features) - count, items = search(search_query, search_params, region).as(Tuple) + items = search(search_query, search_params, region) end # Light processing to flatten search results out of Categories. @@ -254,5 +251,5 @@ def process_search_query(query, page, user, region) end end - {search_query, items_without_category.size, items_without_category, operators} + {search_query, items_without_category, operators} end diff --git a/src/invidious/views/add_playlist_items.ecr b/src/invidious/views/add_playlist_items.ecr index c62861b0..ad50909a 100644 --- a/src/invidious/views/add_playlist_items.ecr +++ b/src/invidious/views/add_playlist_items.ecr @@ -48,7 +48,7 @@