|
|
@ -43,20 +43,20 @@ module Invidious::Routes::API::V1::Search
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def self.search_suggestions(env)
|
|
|
|
def self.search_suggestions(env)
|
|
|
|
locale = env.get("preferences").as(Preferences).locale
|
|
|
|
preferences = env.get("preferences").as(Preferences)
|
|
|
|
region = env.params.query["region"]?
|
|
|
|
region = env.params.query["region"]? || preferences.region
|
|
|
|
|
|
|
|
|
|
|
|
env.response.content_type = "application/json"
|
|
|
|
env.response.content_type = "application/json"
|
|
|
|
|
|
|
|
|
|
|
|
query = env.params.query["q"]?
|
|
|
|
query = env.params.query["q"]? || ""
|
|
|
|
query ||= ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
headers = HTTP::Headers{":authority" => "suggestqueries.google.com"}
|
|
|
|
client = HTTP::Client.new("suggestqueries-clients6.youtube.com")
|
|
|
|
response = YT_POOL.client &.get("/complete/search?hl=en&gl=#{region}&client=youtube&ds=yt&q=#{URI.encode_www_form(query)}&callback=suggestCallback", headers).body
|
|
|
|
url = "/complete/search?client=youtube&hl=en&gl=#{region}&q=#{URI.encode_www_form(query)}&xssi=t&gs_ri=youtube&ds=yt"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response = client.get(url).body
|
|
|
|
|
|
|
|
|
|
|
|
body = response[35..-2]
|
|
|
|
body = JSON.parse(response[5..-1]).as_a
|
|
|
|
body = JSON.parse(body).as_a
|
|
|
|
|
|
|
|
suggestions = body[1].as_a[0..-2]
|
|
|
|
suggestions = body[1].as_a[0..-2]
|
|
|
|
|
|
|
|
|
|
|
|
JSON.build do |json|
|
|
|
|
JSON.build do |json|
|
|
|
|