summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-01-22 16:49:34 -0800
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-01-22 16:49:34 -0800
commit60b57132f163f41291b40c124aba240a392a1884 (patch)
treefc4b4d4d943d475a39b474b9abd7d9b3233b3681
parent8c9e5db8165c5faa92fafed8bbbcbc44e77ca2b5 (diff)
downloadmpv-iptv-menu-60b57132f163f41291b40c124aba240a392a1884.tar.gz
mpv-iptv-menu-60b57132f163f41291b40c124aba240a392a1884.tar.xz
minor improvements to goto operationsHEADmaster
-rw-r--r--catalogue.lua73
-rw-r--r--main.lua46
2 files changed, 69 insertions, 50 deletions
diff --git a/catalogue.lua b/catalogue.lua
index 0eca2f3..5444d17 100644
--- a/catalogue.lua
+++ b/catalogue.lua
@@ -29,6 +29,24 @@ function mt:get(id)
return self.data[id]
end
+function mt:_ensure_catchall(section_id)
+ local id = section_id .. ':category:catchall'
+ local entry = self.data[id]
+ if entry then
+ return entry
+ end
+
+ return self:add({
+ section = section_id,
+ type = 'group',
+ group_type = 'category',
+ id = id,
+ parent_id = section_id .. ':category:0',
+ -- non-ascii symbol to sort near end
+ name = '∗CATCHALL∗',
+ })
+end
+
function mt:add(entry)
self.data[entry.id] = entry
@@ -37,28 +55,25 @@ function mt:add(entry)
end
if not entry.parent_id then
- return
+ return entry
end
+ local parent = self.data[entry.parent_id]
+
-- dump any entries referencing nonexistent categories into a single
-- catchall category
- if not self.data[entry.parent_id] then
- entry.parent_id = entry.section .. ':category:catchall'
- if not self.data[entry.parent_id] then
- self:add({
- section = entry.section,
- type = 'group',
- group_type = 'category',
- id = entry.parent_id,
- parent_id = entry.section .. ':category:0',
- -- non-ascii symbol to sort near end
- name = '∗CATCHALL∗',
- })
- end
+ if not parent then
+ parent = self:_ensure_catchall(entry.section)
+ entry.parent_id = parent.id
+ end
+
+ if parent.id == entry.id then
+ entry.parent_id = nil
+ else
+ parent.children[#parent.children+1] = entry
end
- local parent_children = self.data[entry.parent_id].children
- parent_children[#parent_children+1] = entry
+ return entry
end
function mt:load_xc_section(section)
@@ -111,4 +126,30 @@ function mt:load_xc_section(section)
end
end
+function mt:path_to_root(entry)
+ local path = {}
+
+ local curr = entry
+ while curr.parent_id and curr.parent_id ~= 'root' do
+ curr = self:get(curr.parent_id)
+ if not curr then
+ return
+ end
+ path[#path+1] = curr
+ end
+ if curr.parent_id ~= 'root' then
+ return
+ end
+
+ return path
+end
+
+function mt:path_from_root(entry)
+ local path = self:path_to_root(entry)
+ if path then
+ util.reverse(path)
+ end
+ return path
+end
+
return catalogue
diff --git a/main.lua b/main.lua
index 521c0d5..31c58ab 100644
--- a/main.lua
+++ b/main.lua
@@ -341,22 +341,14 @@ local function favourites_group_menu_options(group)
for _, id in ipairs(state.favourites) do
local obj = catalogue:get(id)
if obj then
- local path = {}
- local curr = obj
- while curr.parent_id and curr.parent_id ~= 'root' and
- catalogue:get(curr.parent_id) do
- curr = catalogue:get(curr.parent_id)
- path[#path+1] = curr
- end
-
obj = util.copy_table(obj)
add_programme(obj, time)
local c = group_count(obj)
if c then
obj.info = tostring(c)
end
- if #path > 0 and curr.parent_id == 'root' then
- util.reverse(path)
+ local path = catalogue:path_from_root(obj)
+ if path then
obj.path = path
end
options[#options+1] = obj
@@ -586,7 +578,7 @@ end
local function goto_option()
local menu = state:menu()
local opt = menu.options[menu.cursor]
- if not opt then
+ if not opt or not opt.path then
return
end
@@ -599,34 +591,20 @@ local function goto_option()
end
end
- if opt.path then
- for i = 1, #opt.path do
- cursor_to_object(opt.path[i].id)
- push_group_menu(opt.path[i])
- end
+ for i = 1, #opt.path do
+ cursor_to_object(opt.path[i].id)
+ push_group_menu(opt.path[i])
end
cursor_to_object(opt.id)
+
osd:dirty()
end
local function goto_playing()
- if not state.playing_id then
- return
- end
-
- local obj = catalogue:get(state.playing_id)
- if not obj then
- return
- end
-
- local path = {}
- local curr = obj
- while curr.parent_id and curr.parent_id ~= 'root' and
- catalogue:get(curr.parent_id) do
- curr = catalogue:get(curr.parent_id)
- path[#path+1] = curr
- end
- if #path == 0 or curr.parent_id ~= 'root' then
+ local id = state.playing_id
+ local obj = id and catalogue:get(id)
+ local path = obj and catalogue:path_to_root(obj)
+ if not path then
return
end
@@ -635,8 +613,8 @@ local function goto_playing()
cursor_to_object(path[i].id)
push_group_menu(path[i])
end
+ cursor_to_object(id)
- cursor_to_object(obj.id)
osd:dirty()
end