Invidious is an alternative front-end to YouTube
Add video refresh
Omar Roth1ea72908929f
diff --git a/config/config.yml b/config/config.ymlindex 3891c228..ad8ccd98 100644--- a/config/config.yml+++ b/config/config.yml@@ -1,5 +1,6 @@-channel_threads: 5threads: 5+channel_threads: 5+video_threads: 5db:user: kemalpassword: kemaldiff --git a/src/helpers.cr b/src/helpers.crindex 6cfe7baa..6d403446 100644--- a/src/helpers.cr+++ b/src/helpers.cr@@ -17,6 +17,7 @@ class ConfigYAML.mapping({threads: Int32,channel_threads: Int32,+ video_threads: Int32,db: NamedTuple(user: String,password: String,diff --git a/src/invidious.cr b/src/invidious.crindex 1948c8e2..aede9904 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -27,6 +27,7 @@ CONFIG = Config.from_yaml(File.read("config/config.yml"))threads = CONFIG.threadschannel_threads = CONFIG.channel_threads+video_threads = CONFIG.video_threadsKemal.config.extra_options do |parser|parser.banner = "Usage: invidious [arguments]"@@ -46,6 +47,14 @@ Kemal.config.extra_options do |parser|exitendend+ parser.on("-v THREADS", "--video-threads=THREADS", "Number of threads for refreshing videos (default: #{video_threads})") do |number|+ begin+ video_threads = number.to_i+ rescue ex+ puts "THREADS must be integer"+ exit+end+ endendKemal::CLI.new@@ -139,6 +148,31 @@ channel_threads.times do |i|endend+video_threads.times do |i|+ spawn do+ loop do+ query = "SELECT id FROM videos ORDER BY updated \+ LIMIT (SELECT count(*)/$2 FROM videos) \+ OFFSET (SELECT count(*)*$1/$2 FROM videos)"+ PG_DB.query(query, i, video_threads) do |rs|+ rs.each do+ client = make_client(YT_URL)++ begin+ id = rs.read(String)+ video = get_video(id, client, PG_DB)+ rescue ex+ STDOUT << id << " : " << ex.message << "\n"+ client = make_client(YT_URL)+ next+ end+ end+ end+ Fiber.yield+ end+ end+end+top_videos = [] of Videospawn do