summaryrefslogtreecommitdiff
path: root/iptv-menu-dl.lua
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2025-05-20 18:52:15 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2025-05-20 18:52:15 -0700
commitbcb9d82a1f4d5b168d11270d7e3fdfd1b9591831 (patch)
treecc135d376c8b0db442f43ce6c4e0ecc08aa8bd1f /iptv-menu-dl.lua
parent55ade5ac655953bef1a7efeeb7fa91ec0fd47a77 (diff)
downloadmpv-iptv-menu-bcb9d82a1f4d5b168d11270d7e3fdfd1b9591831.tar.gz
mpv-iptv-menu-bcb9d82a1f4d5b168d11270d7e3fdfd1b9591831.tar.xz
reimplement downloader using async subprocesses
Diffstat (limited to 'iptv-menu-dl.lua')
-rw-r--r--iptv-menu-dl.lua48
1 files changed, 0 insertions, 48 deletions
diff --git a/iptv-menu-dl.lua b/iptv-menu-dl.lua
deleted file mode 100644
index a207c91..0000000
--- a/iptv-menu-dl.lua
+++ /dev/null
@@ -1,48 +0,0 @@
--- Copyright 2025 David Vazgenovich Shakaryan
-
-local utils = require('mp.utils')
-
-local queue = {}
-
-function download(target, name, url, path)
- if utils.file_info(path) then
- return
- end
-
- local cmd = 'curl -sSfLo \'' .. path .. '\'' .. ' \'' .. url .. '\''
- print('exec: ' .. cmd)
- local ret = os.execute(cmd)
-
- if ret == 0 then
- mp.commandv('script-message-to', target, name, url, path)
- end
-end
-
-function process_next()
- download(unpack(table.remove(queue)))
-
- if #queue > 0 then
- mp.add_timeout(0, process_next)
- end
-end
-
-mp.register_script_message('download-file', function(...)
- queue[#queue+1] = {...}
-
- -- we want the ability for a later request to be downloaded before
- -- earlier ones, e.g., to prioritise the image for the current menu.
- --
- -- using a small timeout between receiving a message and processing it
- -- allows for multiple pending messages to be received before any are
- -- processed. however, immediately scheduling a timer for each request
- -- does not work, as all elapsed timeouts are executed before any new
- -- messages are received.
- --
- -- the workaround is to schedule a timeout only when adding to an empty
- -- queue and have each callback schedule an additional timeout if the
- -- queue is not empty after completion. this effectively results in new
- -- messages being received after each download.
- if #queue == 1 then
- mp.add_timeout(0, process_next)
- end
-end)