diff options
Diffstat (limited to 'main.lua')
-rw-r--r-- | main.lua | 27 |
1 files changed, 13 insertions, 14 deletions
@@ -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') |