Skip to content

Commit 440549f

Browse files
Merge pull request #2952 from iv-org/SamantazFox-patch-1
API: fix suggestions not workin
2 parents bdfe317 + f7b557e commit 440549f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/invidious/routes/api/v1/search.cr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,20 @@ module Invidious::Routes::API::V1::Search
4343
end
4444

4545
def self.search_suggestions(env)
46-
locale = env.get("preferences").as(Preferences).locale
47-
region = env.params.query["region"]?
46+
preferences = env.get("preferences").as(Preferences)
47+
region = env.params.query["region"]? || preferences.region
4848

4949
env.response.content_type = "application/json"
5050

51-
query = env.params.query["q"]?
52-
query ||= ""
51+
query = env.params.query["q"]? || ""
5352

5453
begin
55-
headers = HTTP::Headers{":authority" => "suggestqueries.google.com"}
56-
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
54+
client = HTTP::Client.new("suggestqueries-clients6.youtube.com")
55+
url = "/complete/search?client=youtube&hl=en&gl=#{region}&q=#{URI.encode_www_form(query)}&xssi=t&gs_ri=youtube&ds=yt"
56+
57+
response = client.get(url).body
5758

58-
body = response[35..-2]
59-
body = JSON.parse(body).as_a
59+
body = JSON.parse(response[5..-1]).as_a
6060
suggestions = body[1].as_a[0..-2]
6161

6262
JSON.build do |json|

0 commit comments

Comments
 (0)