summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua72
1 files changed, 44 insertions, 28 deletions
diff --git a/main.lua b/main.lua
index db9f3c4..396e300 100644
--- a/main.lua
+++ b/main.lua
@@ -22,6 +22,7 @@ local colours = {
icon_active='{\\c&H99FF&}',
}
+local script_name = mp.get_script_name()
local script_dir = mp.get_script_directory()
local xc_server = mp.get_opt('iptv_menu.xc_server')
local xc_user = mp.get_opt('iptv_menu.xc_user')
@@ -132,18 +133,17 @@ local function get_image_path(url, dl)
local path = 'img/' .. url:gsub('%W', '_')
local f = utils.file_info(path)
- if not f then
- if not dl then
- return
- end
-
- local cmd = 'curl -sSfLo \'' .. path .. '\'' ..
- ' \'' .. url .. '\''
- print('exec: ' .. cmd)
- os.execute(cmd)
+ if f then
+ return path
end
- return path
+ if dl then
+ mp.commandv('script-message-to',
+ 'iptv_menu_dl', 'download-image',
+ script_name, 'downloaded-image', -- callback
+ url, path)
+ return path
+ end
end
local function add_object(obj)
@@ -421,28 +421,29 @@ local function update_osd_image(path, menu_res)
local x = math.floor(osd_width - padding - w)
local y = math.floor(padding)
- local cmd
-
- if osd_img and path == osd_img.path and w == osd_img.cmd.w and
- h == osd_img.cmd.h then
+ local disp
+ if osd_img and osd_img.loaded and path == osd_img.path and
+ w == osd_img.cmd.w and h == osd_img.cmd.h then
if x == osd_img.cmd.x and y == osd_img.cmd.y then
return
end
- goto disp
+ disp = true
+ else
+ local f = utils.file_info(path)
+ if f then
+ local cmd = 'magick \'' .. path .. '\'' ..
+ ' -background none' ..
+ ' -gravity northwest' ..
+ ' -resize ' .. w .. 'x' .. h ..
+ ' -extent ' .. w .. 'x' .. h ..
+ ' tmp.rgba'
+ print('exec: ' .. cmd)
+ os.execute(cmd)
+ disp = true
+ end
end
- cmd = 'magick \'' .. path .. '\'' ..
- ' -background none' ..
- ' -gravity northwest' ..
- ' -resize ' .. w .. 'x' .. h ..
- ' -extent ' .. w .. 'x' .. h ..
- ' tmp.rgba'
- print('exec: ' .. cmd)
- os.execute(cmd)
-
- ::disp::
- print('reloading img')
osd_img = {
path=path,
cmd={
@@ -458,7 +459,15 @@ local function update_osd_image(path, menu_res)
stride=4*w,
},
}
- mp.command_native(osd_img.cmd)
+
+ if disp then
+ osd_img.loaded = true
+ if not osd.hidden then
+ mp.command_native(osd_img.cmd)
+ end
+ else
+ mp.command_native({name='overlay-remove', id=osd_img.cmd.id})
+ end
end
local function remove_osd_image()
@@ -498,7 +507,7 @@ local function update_osd()
osd_option_path(opt, info)
if selected and opt.stream_icon then
- img = get_image_path(opt.stream_icon)
+ img = get_image_path(opt.stream_icon, true)
end
end
@@ -1336,6 +1345,12 @@ 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
@@ -1358,3 +1373,4 @@ 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')