From bcb9d82a1f4d5b168d11270d7e3fdfd1b9591831 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 20 May 2025 18:52:15 -0700 Subject: reimplement downloader using async subprocesses --- iptv-menu-dl.lua | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) delete mode 100644 iptv-menu-dl.lua (limited to 'iptv-menu-dl.lua') 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) -- cgit v1.2.3-70-g09d2