summaryrefslogtreecommitdiff
path: root/catalogue.lua
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-01-27 01:12:16 -0800
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-01-27 01:16:58 -0800
commit82526665364389d92e0f2c33eba04678275863bb (patch)
tree547f3a797b861e85c79bde7baf87fe5145c0396d /catalogue.lua
parent1d2c82bfb4dcfd71045f2948bb320a94013971a5 (diff)
downloadmpv-iptv-menu-82526665364389d92e0f2c33eba04678275863bb.tar.gz
mpv-iptv-menu-82526665364389d92e0f2c33eba04678275863bb.tar.xz
on-demand calculation and update of option info
Using metatables to calculate info strings on render, we can avoid precomputing it for all options when generating the menu, making certain menus open much faster. This also allows us to update dynamic info, e.g. the currently programme, while the menu is open.
Diffstat (limited to 'catalogue.lua')
-rw-r--r--catalogue.lua87
1 files changed, 28 insertions, 59 deletions
diff --git a/catalogue.lua b/catalogue.lua
index cf9d897..7f83e82 100644
--- a/catalogue.lua
+++ b/catalogue.lua
@@ -14,13 +14,6 @@ function catalogue.new()
id = 'root',
name = '/',
})
- t:add({
- type = 'group',
- id = 'favourites',
- parent_id = 'root',
- name = 'Favourites',
- lazy = true, -- prevent infinite recursion on search
- })
return t
end
@@ -50,7 +43,7 @@ end
function mt:add(entry)
self.data[entry.id] = entry
- if entry.type == 'group' then
+ if entry.type == 'group' and not entry.children_f then
entry.children = {}
end
@@ -76,57 +69,6 @@ function mt:add(entry)
return entry
end
-function mt:load_xc_section(section)
- self:add({
- section = section.id,
- type = 'group',
- group_type = 'category',
- id = section.id .. ':category:0',
- parent_id = 'root',
- name = section.name,
- })
-
- -- currently, this will not correctly handle subcategories which come
- -- before their parent category
- for _, v in ipairs(section.categories) do
- self:add({
- section = section.id,
- type = 'group',
- group_type = 'category',
- id = section.id .. ':category:' .. v.category_id,
- parent_id = section.id .. ':category:' .. v.parent_id,
- name = util.strip(v.category_name),
- })
- end
-
- for _, v in ipairs(section.elements) do
- local vv = {
- section = section.id,
- parent_id = section.id .. ':category:' ..
- v.category_id,
- name = util.strip(v.name),
- }
-
- if section.type == 'series' then
- vv.type = 'group'
- vv.group_type = 'series'
- vv.id = section.id .. ':series:' .. v.series_id
- vv.series_id = v.series_id
- vv.img_url = util.strip_ne(v.cover)
- vv.lazy = true -- avoid API calls on search
- else
- vv.type = 'stream'
- vv.id = section.id .. ':stream:' .. v.stream_id
- vv.stream_type = v.stream_type
- vv.stream_id = v.stream_id
- vv.img_url = util.strip_ne(v.stream_icon)
- vv.epg_channel_id = util.strip_ne(v.epg_channel_id)
- end
-
- self:add(vv)
- end
-end
-
function mt:path_to_root(entry)
local path = {}
@@ -153,4 +95,31 @@ function mt:path_from_root(entry)
return path
end
+function mt:group_count(group)
+ if group.count then
+ return group.count
+ end
+
+ if group.count_f then
+ return group.count_f(group)
+ end
+
+ local count = 0
+ -- only children, not children_f, is considered here. dynamically
+ -- loaded groups will have a count of 0 unless count or count_f is
+ -- specified.
+ for _, v in ipairs(group.children or {}) do
+ if v.type == 'group' then
+ count = count + (v.count or mt:group_count(v) or 0)
+ else
+ count = count + 1
+ end
+ end
+ return count
+end
+
+function mt:group_children(group)
+ return group.children_f and group.children_f(group) or group.children
+end
+
return catalogue