mirror of
https://github.com/iv-org/invidious.git
synced 2024-12-22 21:43:38 +00:00
Add video refresh
This commit is contained in:
parent
6a7d19163e
commit
1ea7290892
@ -1,5 +1,6 @@
|
||||
channel_threads: 5
|
||||
threads: 5
|
||||
channel_threads: 5
|
||||
video_threads: 5
|
||||
db:
|
||||
user: kemal
|
||||
password: kemal
|
||||
|
@ -17,6 +17,7 @@ class Config
|
||||
YAML.mapping({
|
||||
threads: Int32,
|
||||
channel_threads: Int32,
|
||||
video_threads: Int32,
|
||||
db: NamedTuple(
|
||||
user: String,
|
||||
password: String,
|
||||
|
@ -27,6 +27,7 @@ CONFIG = Config.from_yaml(File.read("config/config.yml"))
|
||||
|
||||
threads = CONFIG.threads
|
||||
channel_threads = CONFIG.channel_threads
|
||||
video_threads = CONFIG.video_threads
|
||||
|
||||
Kemal.config.extra_options do |parser|
|
||||
parser.banner = "Usage: invidious [arguments]"
|
||||
@ -46,6 +47,14 @@ Kemal.config.extra_options do |parser|
|
||||
exit
|
||||
end
|
||||
end
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
Kemal::CLI.new
|
||||
@ -139,6 +148,31 @@ channel_threads.times do |i|
|
||||
end
|
||||
end
|
||||
|
||||
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 Video
|
||||
|
||||
spawn do
|
||||
|
Loading…
Reference in New Issue
Block a user