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 --- main.lua | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'main.lua') diff --git a/main.lua b/main.lua index 1d2d252..88e15bc 100644 --- a/main.lua +++ b/main.lua @@ -1,6 +1,7 @@ -- Copyright 2025 David Vazgenovich Shakaryan -local xclib = require('xc') +local _downloader = require('downloader') +local _xc = require('xc') local utils = require('mp.utils') @@ -26,7 +27,8 @@ local colours = { local script_name = mp.get_script_name() local script_dir = mp.get_script_directory() -local xc = xclib.new({ +local downloader = _downloader.new() +local xc = _xc.new({ server = mp.get_opt('iptv_menu.xc_server'), user = mp.get_opt('iptv_menu.xc_user'), pass = mp.get_opt('iptv_menu.xc_pass'), @@ -133,6 +135,8 @@ local function write_json_file(fn, data) f:close() end +local update_osd + local function get_image_path(url, dl) local path = 'img/' .. url:gsub('%W', '_') @@ -142,10 +146,12 @@ local function get_image_path(url, dl) end if dl then - mp.commandv('script-message-to', - 'iptv_menu_dl', 'download-file', - script_name, 'downloaded-image', -- callback - url, path) + downloader:schedule(url, path, function(_, file) + if osd_img and file == osd_img.path then + update_osd() + end + end) + return path end end @@ -480,7 +486,7 @@ local function remove_osd_image() osd_img = nil end -local function update_osd() +function update_osd() local out = {} if depth > 1 then @@ -1366,12 +1372,6 @@ local function toggle_menu() end end -mp.register_script_message('downloaded-image', function(url, path) - if osd_img and path == osd_img.path then - update_osd() - end -end) - mp.observe_property('osd-dimensions', 'native', function(_, val) osd_width = val.w osd_height = val.h @@ -1394,4 +1394,3 @@ mp.add_forced_key_binding('TAB', 'toggle-menu', toggle_menu) bind_menu_keys() load_data() push_group_menu(objects['root']) -mp.commandv('load-script', script_dir .. '/iptv-menu-dl.lua') -- cgit v1.2.3-70-g09d2