From a774d41fdfd333fa0dd7ac1c558febe15638ea16 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Fri, 19 Dec 2025 16:54:46 -0800 Subject: request categories and streams from API --- main.lua | 78 ++++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 26 deletions(-) (limited to 'main.lua') diff --git a/main.lua b/main.lua index acb7646..8ef83d4 100644 --- a/main.lua +++ b/main.lua @@ -114,7 +114,23 @@ local function add_object(obj) parent_children[#parent_children+1] = obj end -local function load_section(section, name) +local function cached_xc_call(method) + local path = mp_utils.join_path( + script_dir, + 'cache/' .. xc.server:gsub('%W', '_') .. '.' .. method) + + local f = io.open(path, 'r') + if f then + f:close() + return util.read_json_file(path) + end + + local data = xc[method](xc) + util.write_json_file(path, data) + return data +end + +local function load_section(section, name, section_type) add_object({ section=section, type='group', @@ -124,34 +140,44 @@ local function load_section(section, name) name=name, }) - local tmp = util.read_json_file( - mp_utils.join_path(script_dir, section .. '_categories.json')) + local tmp = cached_xc_call('get_' .. section_type .. '_categories') for _, v in ipairs(tmp) do - v.section = section - v.type = 'group' - v.group_type = 'category' - v.id = section .. ':category:' .. v.category_id - v.parent_id = section .. ':category:' .. v.parent_id - v.name = util.strip(v.category_name) - add_object(v) + add_object({ + section=section, + type='group', + group_type='category', + id=section .. ':category:' .. v.category_id, + parent_id=section .. ':category:' .. v.parent_id, + name=util.strip(v.category_name), + }) end - local tmp = util.read_json_file( - mp_utils.join_path(script_dir, section .. '_streams.json')) + tmp = cached_xc_call( + section_type == 'series' and 'get_series' or + ('get_' .. section_type .. '_streams')) for _, v in ipairs(tmp) do - v.section = section - if v.series_id then - v.type = 'group' - v.group_type = 'series' - v.id = section .. ':series:' .. v.series_id - v.lazy = true + local vv = { + section=section, + parent_id=section .. ':category:' .. v.category_id, + name=util.strip(v.name), + } + + if section_type == 'series' then + vv.type = 'group' + vv.group_type = 'series' + vv.id = section .. ':series:' .. v.series_id + vv.series_id = v.series_id + vv.stream_icon = v.cover + vv.lazy = true else - v.type = 'stream' - v.id = section .. ':stream:' .. v.stream_id + vv.type = 'stream' + vv.id = section .. ':stream:' .. v.stream_id + vv.stream_type = v.stream_type + vv.stream_id = v.stream_id + vv.stream_icon = v.stream_icon + vv.epg_channel_id = v.epg_channel_id end - v.parent_id = section .. ':category:' .. v.category_id - v.name = util.strip(v.name) - add_object(v) + add_object(vv) end end @@ -209,9 +235,9 @@ local function load_data() lazy=true, }) - load_section('live', 'Live TV') - load_section('movie', 'Movies') - load_section('series', 'Series') + load_section('live', 'Live TV', 'live') + load_section('movie', 'Movies', 'vod') + load_section('series', 'Series', 'series') load_epg() favourites = util.read_json_file( -- cgit v1.2.3-70-g09d2