summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-01-03 20:27:16 -0800
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-01-03 20:27:16 -0800
commit45c38d2dc8f27b2c3dff4a4e6bcd24b7e84e9135 (patch)
tree1a65bb3be6b9aa4916a6140365a5300805436266
parent41434278c6c76e62a215f42c0fefafa573fcbdda (diff)
downloadmpv-iptv-menu-45c38d2dc8f27b2c3dff4a4e6bcd24b7e84e9135.tar.gz
mpv-iptv-menu-45c38d2dc8f27b2c3dff4a4e6bcd24b7e84e9135.tar.xz
avoid duplicate downloads on sequential requests of same URL
-rw-r--r--downloader.lua22
1 files changed, 15 insertions, 7 deletions
diff --git a/downloader.lua b/downloader.lua
index 768d726..a8519dd 100644
--- a/downloader.lua
+++ b/downloader.lua
@@ -29,16 +29,24 @@ function mt:exec(url, file, cb)
args = cmd,
playback_only = false,
}, function(success, res)
- self.running = false
- self:exec_next()
- if success and res.status == 0 then
- os.rename(tmp, file)
- if cb then
- cb(url, file)
- end
+ success = success and res.status == 0
+ if success then
+ success = os.rename(tmp, file)
else
os.remove(tmp)
end
+
+ -- execute next download after renaming the file but before
+ -- executing the callback function. this avoids duplicate
+ -- downloads when the same file is requested twice in a row,
+ -- without unnecessarily waiting for the callback to complete
+ -- before starting the next download.
+ self.running = false
+ self:exec_next()
+
+ if success and cb then
+ cb(url, file)
+ end
end)
end