summaryrefslogtreecommitdiffstats
path: root/src/invidious.cr
diff options
context:
space:
mode:
authorOmar Roth <omarroth@protonmail.com>2019-11-18 17:28:32 -0500
committerOmar Roth <omarroth@protonmail.com>2019-11-18 17:28:32 -0500
commitd46b26e3bc87fbbdfa9550820410041b861bb393 (patch)
tree98f74dbf6ed3db90e5486b2b3586fc8a2f0b6d09 /src/invidious.cr
parent236c172c6ff0aefe70fa34d88024aef20824a8d5 (diff)
downloadinvidious-d46b26e3bc87fbbdfa9550820410041b861bb393.tar.gz
invidious-d46b26e3bc87fbbdfa9550820410041b861bb393.tar.bz2
invidious-d46b26e3bc87fbbdfa9550820410041b861bb393.zip
Use QUIC for connections to YouTube
Diffstat (limited to 'src/invidious.cr')
-rw-r--r--src/invidious.cr10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index 94ea1d92..a766a11c 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -94,7 +94,7 @@ LOCALES = {
"zh-TW" => load_locale("zh-TW"),
}
-YT_POOL = HTTPPool.new(YT_URL, capacity: CONFIG.pool_size, timeout: 0.05)
+YT_POOL = QUICPool.new(YT_URL, capacity: CONFIG.pool_size, timeout: 0.05)
YT_IMG_POOL = HTTPPool.new(YT_IMG_URL, capacity: CONFIG.pool_size, timeout: 0.05)
config = CONFIG
@@ -1435,6 +1435,7 @@ post "/login" do |env|
traceback = IO::Memory.new
# See https://github.com/ytdl-org/youtube-dl/blob/2019.04.07/youtube_dl/extractor/youtube.py#L82
+ # TODO: Convert to QUIC
begin
client = make_client(LOGIN_URL)
headers = HTTP::Headers.new
@@ -1459,7 +1460,7 @@ post "/login" do |env|
headers["Content-Type"] = "application/x-www-form-urlencoded;charset=utf-8"
headers["Google-Accounts-XSRF"] = "1"
- headers["User-Agent"] = random_user_agent
+ headers["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"
response = client.post("/_/signin/sl/lookup", headers, login_req(lookup_req))
lookup_results = JSON.parse(response.body[5..-1])
@@ -4509,8 +4510,9 @@ get "/api/v1/search/suggestions" do |env|
query ||= ""
begin
- client = make_client(URI.parse("https://suggestqueries.google.com"))
- response = client.get("/complete/search?hl=en&gl=#{region}&client=youtube&ds=yt&q=#{URI.encode_www_form(query)}&callback=suggestCallback").body
+ response = QUIC::Client.get(
+ "https://suggestqueries.google.com/complete/search?hl=en&gl=#{region}&client=youtube&ds=yt&q=#{URI.encode_www_form(query)}&callback=suggestCallback"
+ ).body
body = response[35..-2]
body = JSON.parse(body).as_a