Invidious is an alternative front-end to YouTube
Refactor client creation
Omar Roth990bca5af536
diff --git a/src/helpers.cr b/src/helpers.crindex 23cab087..27c49c6e 100644--- a/src/helpers.cr+++ b/src/helpers.cr@@ -209,3 +209,10 @@ def rank_videos(db, n)# Return topreturn top[1..n]end++def make_client(url, context)+ client = HTTP::Client.new(URL, CONTEXT)+ client.read_timeout = 10.seconds+ client.connect_timeout = 10.seconds+ return client+enddiff --git a/src/invidious.cr b/src/invidious.crindex 592028e3..8573d2a5 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -48,10 +48,7 @@ CONTEXT.add_options(OpenSSL::SSL::Options::NO_SSL_V3)pool = Deque.new((threads * 1.2 + 1).to_i) do- client = HTTP::Client.new(URL, CONTEXT)- client.read_timeout = 10.seconds- client.connect_timeout = 10.seconds- client+ make_client(URL, CONTEXT)end# Refresh pool by crawling YT@@ -74,10 +71,7 @@ threads.times doendif rand(300) < 1- client = HTTP::Client.new(URL, CONTEXT)- client.read_timeout = 10.seconds- client.connect_timeout = 10.seconds- pool << client+ pool << make_client(URL, CONTEXT)endtime = Time.now@@ -87,10 +81,7 @@ threads.times dovideo = get_video(id, client, PG_DB)rescue exio << id << " : " << ex << "\n"- client = HTTP::Client.new(URL, CONTEXT)- client.read_timeout = 10.seconds- client.connect_timeout = 10.seconds- pool << client+ pool << make_client(URL, CONTEXT)nextensureids.delete(id)