From e1f7209131cafab74f0665599a13d668ebeb410c Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Fri, 6 Feb 2026 12:30:32 -0800 Subject: implement global EPG search --- rx.lua | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'rx.lua') diff --git a/rx.lua b/rx.lua index d96420f..0c85029 100644 --- a/rx.lua +++ b/rx.lua @@ -281,6 +281,7 @@ function rx.menu_options_channel_epg(src_id, ch) local time = os.time() for i, v in ipairs(progs) do local prog = { + id = ch .. ':' .. i, name = os.date('%a %d %b %H:%M', v.start) .. ' ' .. os.date('%H:%M', v.stop) .. ' ' .. v.title, type = 'programme', @@ -315,6 +316,64 @@ function rx.menu_options_programme_info(prog) return options end +local function menu_options_epg_search_build_progs(options, opt, path, time) + local ch = opt.epg_channel_id + local progs = ctx.src[opt.src_id].epg:channel_programmes(ch) + if not progs then + return + end + + for i, v in ipairs(progs) do + if time < v.stop then + options[#options+1] = setmetatable({ + id = ch .. ':' .. i, + name = os.date('%a %d %b %H:%M', v.start) .. + ' ' .. os.date('%H:%M', v.stop) .. + ' ' .. v.title, + type = 'programme', + programme = v, + path = path, + }, programme_mt) + end + end +end + +local function menu_options_epg_search_build(options, opts, path, seen, time) + for _, v in ipairs(opts) do + if v.id and not seen[v.id] then + seen[v.id] = true + path[#path+1] = v + if v.epg_channel_id then + menu_options_epg_search_build_progs( + options, v, util.copy_table(path), + time) + elseif v.type == 'group' and v.children then + menu_options_epg_search_build( + options, v.children, path, seen, time) + end + path[#path] = nil + end + end +end + +function rx.menu_options_epg_search(opts) + local options = {} + local time = os.time() + + menu_options_epg_search_build(options, opts, {}, {}, time) + table.sort(options, function(a, b) + if a.programme.start ~= b.programme.start then + return a.programme.start < b.programme.start + end + if a.programme.title ~= b.programme.title then + return a.programme.title < b.programme.title + end + return a.path[#a.path].name < b.path[#b.path].name + end) + + return options +end + local function menu_options_search_build(options, t, path) for _, v in ipairs(options) do v.path = path -- cgit v1.2.3-70-g09d2