summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.lua3
-rw-r--r--xc.lua62
2 files changed, 50 insertions, 15 deletions
diff --git a/main.lua b/main.lua
index 8ef83d4..926a455 100644
--- a/main.lua
+++ b/main.lua
@@ -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 = {
diff --git a/xc.lua b/xc.lua
index a934e42..b96d2a1 100644
--- a/xc.lua
+++ b/xc.lua
@@ -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)