Invidious is an alternative front-end to YouTube
Try using connection pool for getting videos
Omar Rothdfdeb02c7f8b
diff --git a/src/invidious.cr b/src/invidious.crindex 6d84b1e1..ca3a40da 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -7,6 +7,10 @@ require "time"PG_DB = DB.open "postgres://kemal:kemal@localhost:5432/invidious"CONTEXT = OpenSSL::SSL::Context::Client.insecure+POOL = [] of HTTP::Client+10.times do+ POOL << HTTP::Client.new("www.youtube.com", 443, CONTEXT)+endmacro templated(filename)render "src/views/#{{{filename}}}.ecr", "src/views/layout.ecr"@@ -66,7 +70,10 @@ def ci_lower_bound(pos, n)enddef fetch_video(id)- client = HTTP::Client.new("www.youtube.com", 443, CONTEXT)+ # Grab connection from pool+ client = POOL.pop++ # client = HTTP::Client.new("www.youtube.com", 443, CONTEXT)info = client.get("/get_video_info?video_id=#{id}&el=info&ps=default&eurl=&gl=US&hl=en").bodyinfo = HTTP::Params.parse(info)@@ -77,8 +84,11 @@ def fetch_video(id)raise info["reason"]end+ # Return connection to pool+ POOL << client+video = Video.new(id, info, html, Time.now)-+return videoend@@ -186,7 +196,8 @@ endget "/search" do |env|query = env.params.query["q"]- client = HTTP::Client.new("www.youtube.com", 443, CONTEXT)+ client = POOL.pop+html = client.get("https://www.youtube.com/results?q=#{URI.escape(query)}&page=1").bodyhtml = XML.parse(html)@@ -208,6 +219,8 @@ get "/search" do |env|endend+ POOL << client+templated "search"end