Invidious is an alternative front-end to YouTube
Get videos from search
Omar Roth02b699024041
diff --git a/src/invidious.cr b/src/invidious.crindex 8591c9d7..5f580edb 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -21,23 +21,45 @@ POOL = Deque.new(30) doclientend-# Refresh all the connections in the pool by crawling recommended+# Refresh connections by crawling YTspawn do- # Arbitrary start value- id = Deque.new(50, "0xjKNDMgE54")+ # Start video+ id = Deque.new(10, "_wbqqI0IgY8")++ client = get_client+ random = Random.new+ html = client.get("https://www.youtube.com/results?q=#{random.base64(3)}&sp=EgIQAVAU").body+ html = XML.parse_html(html)++ html.xpath_nodes(%q(//ol[@class="item-section"]/li)).each do |item|+ root = item.xpath_node(%q(div[contains(@class,"yt-lockup-video")]/div))+ if root+ link = root.xpath_node(%q(div[contains(@class,"yt-lockup-thumbnail")]/a/@href))+ if link+ id << link.content.split("=")[1]+ id.shift+ end+ end+ end++ POOL << client+loop do+ if rand(600) < 1client = get_client- if rand(100) < 1client = HTTP::Client.new(URL, CONTEXT)client.connect_timeout = Time::Span.new(0, 0, 0, 5)+ POOL << clientend+time = Time.nowbegin- video = get_video(id[rand(id.size)], false)+ i = id[rand(id.size)]+ video = get_video(i, false)+ id.delete(i)rescue exputs ex- POOL << clientnextend@@ -50,13 +72,16 @@ spawn dorvs.each do |rv|if rv.has_key?("id")+ if !PG_DB.query_one?("SELECT EXISTS (SELECT true FROM videos WHERE id = $1)", rv["id"], as: Bool)id << rv["id"]+ if id.size == 50id.shiftendend+ end+ end- POOL << client- puts "#{Time.now} 200 GET youtube.com/watch?v=#{video.id} #{elapsed_text(Time.now - time)}"+ puts "#{Time.now} 200 GET www.youtube.com/watch?v=#{video.id} #{elapsed_text(Time.now - time)}"endend