From 0793df89e4a018c6abe662181a564ec137b2487a Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 19 Jan 2026 20:38:29 -0800 Subject: use tmpfs for bgra images, delete on shutdown --- config.lua | 1 + main.lua | 4 ++++ osd.lua | 18 ++++++++++++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/config.lua b/config.lua index d42e3b0..858624e 100644 --- a/config.lua +++ b/config.lua @@ -41,6 +41,7 @@ config.colours = { } local script_dir = mp.get_script_directory() +config.tmp_dir = os.getenv('XDG_RUNTIME_DIR') or '/tmp' config.cache_dir = mp_utils.join_path(script_dir, 'cache') config.img_dir = mp_utils.join_path(script_dir, 'img') config.favourites_file = mp_utils.join_path(script_dir, 'favourites.json') diff --git a/main.lua b/main.lua index b9046b7..9e8a888 100644 --- a/main.lua +++ b/main.lua @@ -1355,6 +1355,10 @@ mp.register_event('end-file', function() osd:redraw(state) end) +mp.register_event('shutdown', function() + osd:destroy() +end) + state:push_menu({title = 'mpv-iptv-menu'}) osc_visibility = mp.get_property_native('user-data/osc/visibility', 'auto') diff --git a/osd.lua b/osd.lua index 2cd1be2..3be5e2d 100644 --- a/osd.lua +++ b/osd.lua @@ -19,6 +19,10 @@ for k, v in pairs(config.colours) do colours[k] = '{\\c&H' .. tag end +local bgra_file = mp_utils.join_path( + config.tmp_dir, + mp.get_script_name() .. '-' .. mp_utils.getpid() .. '.bgra') + local function draw_rect(x1, y1, x2, y2) return string.format( '{\\p1}m %f %f l %f %f %f %f %f %f{\\p0}', @@ -57,6 +61,16 @@ function osd.new(init) return t end +function mt:destroy() + if self.magick_cmd_id then + mp.abort_async_command(self.magick_cmd_id) + end + + if mp_utils.file_info(bgra_file) then + os.remove(bgra_file) + end +end + function mt:dirty() self.is_dirty = true end @@ -256,7 +270,7 @@ function mt:load_img() self.img.min_h, self.img.min_w, self.img.max_h, self.img.max_w), '-print', '%w %h', - 'tmp.bgra' + bgra_file } print('exec: ' .. mp_utils.to_string(magick_cmd)) self.img.magick_cmd = magick_cmd @@ -289,7 +303,7 @@ function mt:load_img() self.img.cmd = { name = 'overlay-add', id = 0, - file = 'tmp.bgra', + file = bgra_file, w = w, h = h, x = self.img.right - w, -- cgit v1.2.3-70-g09d2