summaryrefslogtreecommitdiff
path: root/downloader.lua
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2025-05-20 20:29:31 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2025-05-20 20:29:31 -0700
commit29e4c12898b232ec7c3af563f27aa1f5638fe0da (patch)
treea9cdbf3c1c0814455163e510f7b3694ded9927fa /downloader.lua
parent8fbfafa62bf8483e5385226a245f8481ee021c45 (diff)
downloadmpv-iptv-menu-29e4c12898b232ec7c3af563f27aa1f5638fe0da.tar.gz
mpv-iptv-menu-29e4c12898b232ec7c3af563f27aa1f5638fe0da.tar.xz
use temp file during download
Diffstat (limited to 'downloader.lua')
-rw-r--r--downloader.lua14
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