mirror of
https://github.com/iv-org/invidious.git
synced 2024-10-01 01:35:38 -04:00
fix search
Put search page in the super secret proto field
This commit is contained in:
parent
705e4fca06
commit
2600695927
@ -65,15 +65,15 @@ describe "Helper" do
|
|||||||
|
|
||||||
describe "#produce_search_params" do
|
describe "#produce_search_params" do
|
||||||
it "correctly produces token for searching with specified filters" do
|
it "correctly produces token for searching with specified filters" do
|
||||||
produce_search_params.should eq("CAASAhAB")
|
produce_search_params.should eq("CAASAhABSAA%3D")
|
||||||
|
|
||||||
produce_search_params(sort: "upload_date", content_type: "video").should eq("CAISAhAB")
|
produce_search_params(sort: "upload_date", content_type: "video").should eq("CAISAhABSAA%3D")
|
||||||
|
|
||||||
produce_search_params(content_type: "playlist").should eq("CAASAhAD")
|
produce_search_params(content_type: "playlist").should eq("CAASAhADSAA%3D")
|
||||||
|
|
||||||
produce_search_params(sort: "date", content_type: "video", features: ["hd", "cc", "purchased", "hdr"]).should eq("CAISCxABIAEwAUgByAEB")
|
produce_search_params(sort: "date", content_type: "video", features: ["hd", "cc", "purchased", "hdr"]).should eq("CAISCxABIAEwAUgByAEBSAA%3D")
|
||||||
|
|
||||||
produce_search_params(content_type: "channel").should eq("CAASAhAC")
|
produce_search_params(content_type: "channel").should eq("CAASAhACSAA%3D")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2560,12 +2560,12 @@ get "/api/v1/search" do |env|
|
|||||||
content_type ||= "video"
|
content_type ||= "video"
|
||||||
|
|
||||||
begin
|
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
|
rescue ex
|
||||||
next error_json(400, ex)
|
next error_json(400, ex)
|
||||||
end
|
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.build do |json|
|
||||||
json.array do
|
json.array do
|
||||||
search_results.each do |item|
|
search_results.each do |item|
|
||||||
|
@ -249,10 +249,10 @@ def channel_search(query, page, channel)
|
|||||||
return items.size, items
|
return items.size, items
|
||||||
end
|
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?
|
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?
|
return 0, [] of SearchItem if body.empty?
|
||||||
|
|
||||||
initial_data = extract_initial_data(body)
|
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
|
return items.size, items
|
||||||
end
|
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)
|
duration : String = "", features : Array(String) = [] of String)
|
||||||
object = {
|
object = {
|
||||||
"1:varint" => 0_i64,
|
"1:varint" => 0_i64,
|
||||||
"2:embedded" => {} of String => Int64,
|
"2:embedded" => {} of String => Int64,
|
||||||
|
"9:varint" => ((page - 1) * 20).to_i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
case sort
|
case sort
|
||||||
@ -439,10 +440,10 @@ def process_search_query(query, page, user, region)
|
|||||||
count = 0
|
count = 0
|
||||||
end
|
end
|
||||||
else
|
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)
|
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
|
end
|
||||||
|
|
||||||
{search_query, count, items, operators}
|
{search_query, count, items, operators}
|
||||||
|
Loading…
Reference in New Issue
Block a user