From 77b12b6249db4e27c5014202b3e8ca17acaf306b Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sat, 25 Aug 2018 17:18:43 -0500 Subject: [PATCH] Only show next page when there are more results --- src/invidious.cr | 4 ++-- src/invidious/jobs.cr | 4 ++-- src/invidious/search.cr | 2 +- src/invidious/views/search.ecr | 2 ++ 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index e36f28f1..9e12de40 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -425,7 +425,7 @@ get "/search" do |env| page ||= 1 search_params = build_search_params(sort_by: "relevance", content_type: "video") - videos = search(query, page, search_params) + count, videos = search(query, page, search_params).as(Tuple) templated "search" end @@ -2365,7 +2365,7 @@ get "/api/v1/search" do |env| response = JSON.build do |json| json.array do - search_results = search(query, page, search_params) + count, search_results = search(query, page, search_params).as(Tuple) search_results.each do |video| json.object do json.field "title", video.title diff --git a/src/invidious/jobs.cr b/src/invidious/jobs.cr index a85244a3..1bc550ad 100644 --- a/src/invidious/jobs.cr +++ b/src/invidious/jobs.cr @@ -2,13 +2,13 @@ def crawl_videos(db) ids = Deque(String).new random = Random.new - search(random.base64(3)).each do |video| + search(random.base64(3)).as(Tuple)[1].each do |video| ids << video.id end loop do if ids.empty? - search(random.base64(3)).each do |video| + search(random.base64(3)).as(Tuple)[1].each do |video| ids << video.id end end diff --git a/src/invidious/search.cr b/src/invidious/search.cr index 8ed18437..04db3098 100644 --- a/src/invidious/search.cr +++ b/src/invidious/search.cr @@ -23,7 +23,7 @@ def search(query, page = 1, search_params = build_search_params(content_type: "v nodeset = html.xpath_nodes(%q(//ol[@class="item-section"]/li)) videos = extract_videos(nodeset) - return videos + return {nodeset.size, videos} end def build_search_params(sort_by = "relevance", date : String = "", content_type : String = "", duration : String = "", features : Array(String) = [] of String) diff --git a/src/invidious/views/search.ecr b/src/invidious/views/search.ecr index 192db364..85b6e416 100644 --- a/src/invidious/views/search.ecr +++ b/src/invidious/views/search.ecr @@ -18,6 +18,8 @@
+ <% if count == 20 %> Next page + <% end %>