summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.lua78
-rw-r--r--xc.lua49
2 files changed, 91 insertions, 36 deletions
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(
diff --git a/xc.lua b/xc.lua
index c7f311e..a934e42 100644
--- a/xc.lua
+++ b/xc.lua
@@ -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/' ..