diff options
| author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2025-12-19 16:54:46 -0800 |
|---|---|---|
| committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2025-12-19 16:54:46 -0800 |
| commit | a774d41fdfd333fa0dd7ac1c558febe15638ea16 (patch) | |
| tree | 6504d3261d820d552094b728caedf653e3768948 | |
| parent | 48fcfe19baae31c2e1635c911f7383d6d58d2aa1 (diff) | |
| download | mpv-iptv-menu-a774d41fdfd333fa0dd7ac1c558febe15638ea16.tar.gz mpv-iptv-menu-a774d41fdfd333fa0dd7ac1c558febe15638ea16.tar.xz | |
request categories and streams from API
| -rw-r--r-- | main.lua | 78 | ||||
| -rw-r--r-- | xc.lua | 49 |
2 files changed, 91 insertions, 36 deletions
@@ -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( @@ -15,28 +15,57 @@ function xc.new(t) end function mt:get(params) - local cmd = 'curl -sSfL \'' .. self.server .. '/player_api.php' .. + local url = self.server .. '/player_api.php' .. '?username=' .. self.user .. '&password=' .. self.pass for k, v in pairs(params) do - cmd = cmd .. '&' .. k .. '=' .. v + url = url .. '&' .. k .. '=' .. v end - cmd = cmd .. '\'' + local cmd = {'curl', '-sSfL', url} + print('querying ' .. url) - print('exec: ' .. cmd) - local fd = io.popen(cmd) - local json = fd:read('*all') - fd:close() - return mp_utils.parse_json(json) + local res = mp.command_native({ + name = 'subprocess', + args = cmd, + capture_stdout = true, + playback_only = false, + }) + if res.status == 0 then + return mp_utils.parse_json(res.stdout) + end end -function mt:get_series_info(id) - return self:get({action = 'get_series_info', series_id = id}) +function mt:get_live_categories() + return self:get({action = 'get_live_categories'}) +end + +function mt:get_live_streams() + return self:get({action = 'get_live_streams'}) +end + +function mt:get_vod_categories() + return self:get({action = 'get_vod_categories'}) +end + +function mt:get_vod_streams() + return self:get({action = 'get_vod_streams'}) end function mt:get_vod_info(id) return self:get({action = 'get_vod_info', vod_id = id}) end +function mt:get_series_categories() + return self:get({action = 'get_series_categories'}) +end + +function mt:get_series() + return self:get({action = 'get_series'}) +end + +function mt:get_series_info(id) + return self:get({action = 'get_series_info', series_id = id}) +end + function mt:stream_url(stream_type, stream_id) if stream_type == 'series' then return self.server .. '/series/' .. |
