diff options
-rw-r--r-- | downloader.lua | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/downloader.lua b/downloader.lua index 67fb675..7fee596 100644 --- a/downloader.lua +++ b/downloader.lua @@ -19,8 +19,9 @@ function mt:exec(url, file, cb) return end - local cmd = {'curl', '-sSfLo', file, url} - print('exec: ' .. utils.to_string(cmd)) + local tmp = file .. '.tmp' + local cmd = {'curl', '-sSfLo', tmp, url} + print('downloading ' .. url) self.running = true mp.command_native_async({ @@ -30,8 +31,13 @@ function mt:exec(url, file, cb) }, function(success, res) self.running = false self:exec_next() - if cb and success and res.status == 0 then - cb(url, file) + if success and res.status == 0 then + os.rename(tmp, file) + if cb then + cb(url, file) + end + else + os.remove(tmp) end end) end |