summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-02-03 16:13:14 -0600
committerOmar Roth <omarroth@hotmail.com>2018-02-03 16:13:14 -0600
commit03aeb27b4051e22b01a0bf435bf7ff388914a2be (patch)
tree22e2064df857e3c10d268d431ad3e6c4f52ac272
parent1e2139d78c41f4e5facb1d2b4cf9c270a96544ff (diff)
downloadinvidious-03aeb27b4051e22b01a0bf435bf7ff388914a2be.tar.gz
invidious-03aeb27b4051e22b01a0bf435bf7ff388914a2be.tar.bz2
invidious-03aeb27b4051e22b01a0bf435bf7ff388914a2be.zip
Add ability to specify number of threads
-rw-r--r--src/invidious.cr21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index 39587989..19ecd4c0 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -15,10 +15,29 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
require "kemal"
+require "option_parser"
require "pg"
require "xml"
require "./helpers"
+threads = 10
+
+OptionParser.parse! do |parser|
+ parser.banner = "Usage: invidious [arguments]"
+ parser.on("-t THREADS", "--threads=THREADS", "Number of threads for crawling") do |number|
+ begin
+ threads = number.to_i32
+ rescue ex
+ puts "THREADS must be integer"
+ exit
+ end
+ end
+ parser.on("-h", "--help", "Show this help") do
+ puts parser
+ exit
+ end
+end
+
PG_DB = DB.open "postgres://kemal:kemal@localhost:5432/invidious"
URL = URI.parse("https://www.youtube.com")
CONTEXT = OpenSSL::SSL::Context::Client.new
@@ -36,7 +55,7 @@ POOL = Deque.new(30) do
end
# Refresh pool by crawling YT
-10.times do
+threads.times do
spawn do
io = STDOUT
ids = Deque(String).new