diff options
| author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-01-03 20:27:16 -0800 |
|---|---|---|
| committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-01-03 20:27:16 -0800 |
| commit | 45c38d2dc8f27b2c3dff4a4e6bcd24b7e84e9135 (patch) | |
| tree | 1a65bb3be6b9aa4916a6140365a5300805436266 | |
| parent | 41434278c6c76e62a215f42c0fefafa573fcbdda (diff) | |
| download | mpv-iptv-menu-45c38d2dc8f27b2c3dff4a4e6bcd24b7e84e9135.tar.gz mpv-iptv-menu-45c38d2dc8f27b2c3dff4a4e6bcd24b7e84e9135.tar.xz | |
avoid duplicate downloads on sequential requests of same URL
| -rw-r--r-- | downloader.lua | 22 |
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 |
