Invidious is an alternative front-end to YouTube
Ensure clients are recycled properly
Omar Rothecb1999795a2
diff --git a/src/invidious.cr b/src/invidious.crindex 5497ad3a..5373a84d 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -63,7 +63,11 @@ threads.times doids << idend+ pool << client+loop do+ client = get_client(pool)+if ids.empty?search(random.base64(3), client) do |id|ids << id@@ -72,10 +76,9 @@ threads.times doif rand(300) < 1pool << make_client(URL, CONTEXT)+ client = get_client(pool)end- time = Time.now-beginid = ids[0]video = get_video(id, client, PG_DB)@@ -104,7 +107,7 @@ threads.times doendend- # io << Time.now << " 200 GET www.youtube.com/watch?v=" << video.id << " " << elapsed_text(Time.now - time) << "\n"+ pool << clientendendend@@ -113,7 +116,7 @@ top_videos = [] of Videospawn doloop do- top = rank_videos(PG_DB, 120)+ top = rank_videos(PG_DB, 40)client = get_client(pool)args = [] of String@@ -121,16 +124,18 @@ spawn doargs << "($#{top.size}) "args = args.join("")+ videos = [] of Video+PG_DB.query("SELECT * FROM videos d INNER JOIN (VALUES #{args}) v(id) USING (id)", top) do |rs|rs.each dovideo = rs.read(Video)- top_videos << video+ videos << videoendend- pool << client+ top_videos = videos- sleep 5.minutes+ pool << clientendend