From 7ac2ea605b5ef7d5bf2b6d54bb1125714de856a2 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 6 May 2025 23:11:24 -0700 Subject: prioritise categories in search results --- main.lua | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/main.lua b/main.lua index e768539..613484b 100644 --- a/main.lua +++ b/main.lua @@ -152,8 +152,10 @@ local function push_menu(t) page_pos=1, } - for k, v in pairs(t) do - menu[k] = v + if t then + for k, v in pairs(t) do + menu[k] = v + end end depth = depth + 1 @@ -232,19 +234,33 @@ local function search_update_osd() update_osd() end -local function search_menu_options(options, arr) +local function search_menu_options_build(options, t) local menu = menus[depth] - local arr = arr or {} for _, v in ipairs(options) do - arr[#arr+1] = v + if not t[v.type] then + t[v.type] = {} + end + t[v.type][#t[v.type]+1] = v if v.type == 'category' then - search_menu_options( - category_menu_options(v.category_id), arr) + search_menu_options_build( + category_menu_options(v.category_id), t) + end + end +end + +local function search_menu_options(options) + local t = {} + search_menu_options_build(options, t) + + local ret = t.category or {} + if t.stream then + for _, v in ipairs(t.stream) do + ret[#ret+1] = v end end - return arr + return ret end local function search_update() -- cgit v1.2.3-70-g09d2