diff options
| -rw-r--r-- | downloader.lua | 17 | ||||
| -rw-r--r-- | main.lua | 2 |
2 files changed, 13 insertions, 6 deletions
diff --git a/downloader.lua b/downloader.lua index a8519dd..7881129 100644 --- a/downloader.lua +++ b/downloader.lua @@ -6,11 +6,13 @@ local downloader = {} local mt = {} mt.__index = mt -function downloader.new() - return setmetatable({ - pending = {}, - running = false, - }, mt) +function downloader.new(t) + t = setmetatable(t or {}, mt) + + t.pending = {} + t.running = false + + return t end function mt:exec(url, file, cb) @@ -60,6 +62,11 @@ end -- likely to be used for the current display state function mt:schedule(...) if self.running then + if self.limit and #self.pending >= self.limit then + -- remove oldest + table.remove(self.pending, 1) + end + self.pending[#self.pending+1] = {...} else self:exec(...) @@ -17,7 +17,7 @@ local script_dir = mp.get_script_directory() local state = _state.new() -local downloader = _downloader.new() +local downloader = _downloader.new({limit = 5}) local xc = _xc.new({ server = mp.get_opt('iptv_menu.xc_server'), user = mp.get_opt('iptv_menu.xc_user'), |
