diff options
| author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2025-12-19 20:57:26 -0800 |
|---|---|---|
| committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2025-12-19 20:57:26 -0800 |
| commit | 6c2c8d7522354531d70103bad60283f40f45011e (patch) | |
| tree | 6c481ace882e3180f64cfbc680aa268356cf176b | |
| parent | a774d41fdfd333fa0dd7ac1c558febe15638ea16 (diff) | |
| download | mpv-iptv-menu-6c2c8d7522354531d70103bad60283f40f45011e.tar.gz mpv-iptv-menu-6c2c8d7522354531d70103bad60283f40f45011e.tar.xz | |
request EPG from API
| -rw-r--r-- | main.lua | 3 | ||||
| -rw-r--r-- | xc.lua | 62 |
2 files changed, 50 insertions, 15 deletions
@@ -197,8 +197,7 @@ local function epg_parse_time(str) end local function load_epg() - local tmp = util.read_json_file( - mp_utils.join_path(script_dir, 'epg.json')) + local tmp = cached_xc_call('get_epg') for _, v in ipairs(tmp) do local ch = v.channel:lower() local prog = { @@ -14,10 +14,12 @@ function xc.new(t) return setmetatable(t, mt) end -function mt:get(params) - local url = self.server .. '/player_api.php' .. - '?username=' .. self.user .. '&password=' .. self.pass - for k, v in pairs(params) do +function mt:get(path, params) + local url = + self.server .. path .. + '?username=' .. self.user .. + '&password=' .. self.pass + for k, v in pairs(params or {}) do url = url .. '&' .. k .. '=' .. v end local cmd = {'curl', '-sSfL', url} @@ -30,40 +32,74 @@ function mt:get(params) playback_only = false, }) if res.status == 0 then - return mp_utils.parse_json(res.stdout) + return res.stdout end end +function mt:api_get(params) + return mp_utils.parse_json(self:get('/player_api.php', params)) +end + function mt:get_live_categories() - return self:get({action = 'get_live_categories'}) + return self:api_get({action = 'get_live_categories'}) end function mt:get_live_streams() - return self:get({action = 'get_live_streams'}) + return self:api_get({action = 'get_live_streams'}) end function mt:get_vod_categories() - return self:get({action = 'get_vod_categories'}) + return self:api_get({action = 'get_vod_categories'}) end function mt:get_vod_streams() - return self:get({action = 'get_vod_streams'}) + return self:api_get({action = 'get_vod_streams'}) end function mt:get_vod_info(id) - return self:get({action = 'get_vod_info', vod_id = id}) + return self:api_get({action = 'get_vod_info', vod_id = id}) end function mt:get_series_categories() - return self:get({action = 'get_series_categories'}) + return self:api_get({action = 'get_series_categories'}) end function mt:get_series() - return self:get({action = 'get_series'}) + return self:api_get({action = 'get_series'}) end function mt:get_series_info(id) - return self:get({action = 'get_series_info', series_id = id}) + return self:api_get({action = 'get_series_info', series_id = id}) +end + +function mt:get_epg() + local xml = self:get('/xmltv.php') + + -- this is a bit retarded, but using python to convert xml to json + -- avoids having to write an xml parser or pull in external + -- dependencies + local cmd = {'python', '-c', [[ +import json +import sys +import xml.etree.ElementTree as ET + +json.dump( + [ + {**{x.tag: x.text for x in p}, **p.attrib} + for p in ET.parse(sys.stdin).iter('programme')], + sys.stdout) +]]} + + local res = mp.command_native({ + name = 'subprocess', + args = cmd, + stdin_data = xml, + capture_stdout = true, + playback_only = false, + }) + if res.status == 0 then + return mp_utils.parse_json(res.stdout) + end end function mt:stream_url(stream_type, stream_id) |
