diff options
| author | TheFrenchGhosty <47571719+TheFrenchGhosty@users.noreply.github.com> | 2021-03-01 22:02:37 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-01 22:02:37 +0000 |
| commit | 44f30c0e056a7d9b57c4093f06f6f0a7ad8def05 (patch) | |
| tree | 7c011ae55c136fd33cabc72a67b3ea5771353338 /src | |
| parent | 489d0151ad0e72b875729b4a7839cc0df2692571 (diff) | |
| parent | 2600695927311062fc9e6abd980bb33f73fe75a6 (diff) | |
| download | invidious-44f30c0e056a7d9b57c4093f06f6f0a7ad8def05.tar.gz invidious-44f30c0e056a7d9b57c4093f06f6f0a7ad8def05.tar.bz2 invidious-44f30c0e056a7d9b57c4093f06f6f0a7ad8def05.zip | |
Merge pull request #1817 from tenpura-shrimp/master
fix search
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious.cr | 4 | ||||
| -rw-r--r-- | src/invidious/search.cr | 11 |
2 files changed, 8 insertions, 7 deletions
diff --git a/src/invidious.cr b/src/invidious.cr index 563a3768..07a445b0 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -2560,12 +2560,12 @@ get "/api/v1/search" do |env| content_type ||= "video" begin - search_params = produce_search_params(sort_by, date, content_type, duration, features) + search_params = produce_search_params(page, sort_by, date, content_type, duration, features) rescue ex next error_json(400, ex) end - count, search_results = search(query, page, search_params, region).as(Tuple) + count, search_results = search(query, search_params, region).as(Tuple) JSON.build do |json| json.array do search_results.each do |item| diff --git a/src/invidious/search.cr b/src/invidious/search.cr index 1c4bc74e..cf8fd790 100644 --- a/src/invidious/search.cr +++ b/src/invidious/search.cr @@ -249,10 +249,10 @@ def channel_search(query, page, channel) return items.size, items end -def search(query, page = 1, search_params = produce_search_params(content_type: "all"), region = nil) +def search(query, search_params = produce_search_params(content_type: "all"), region = nil) return 0, [] of SearchItem if query.empty? - body = YT_POOL.client(region, &.get("/results?q=#{URI.encode_www_form(query)}&page=#{page}&sp=#{search_params}&hl=en").body) + body = YT_POOL.client(region, &.get("/results?search_query=#{URI.encode_www_form(query)}&sp=#{search_params}&hl=en").body) return 0, [] of SearchItem if body.empty? initial_data = extract_initial_data(body) @@ -263,11 +263,12 @@ def search(query, page = 1, search_params = produce_search_params(content_type: return items.size, items end -def produce_search_params(sort : String = "relevance", date : String = "", content_type : String = "", +def produce_search_params(page = 1, sort : String = "relevance", date : String = "", content_type : String = "", duration : String = "", features : Array(String) = [] of String) object = { "1:varint" => 0_i64, "2:embedded" => {} of String => Int64, + "9:varint" => ((page - 1) * 20).to_i64, } case sort @@ -439,10 +440,10 @@ def process_search_query(query, page, user, region) count = 0 end else - search_params = produce_search_params(sort: sort, date: date, content_type: content_type, + search_params = produce_search_params(page: page, sort: sort, date: date, content_type: content_type, duration: duration, features: features) - count, items = search(search_query, page, search_params, region).as(Tuple) + count, items = search(search_query, search_params, region).as(Tuple) end {search_query, count, items, operators} |
