-- Copyright 2025 David Vazgenovich Shakaryan local mp_utils = require('mp.utils') local xc = {} local mt = {} mt.__index = mt function xc.new(t) assert(t.server) assert(t.user) assert(t.pass) 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 url = url .. '&' .. k .. '=' .. v end local cmd = {'curl', '-sSfL', url} print('querying ' .. url) 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_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/' .. self.user .. '/' .. self.pass .. '/' .. stream_id .. '.vod' else return self.server .. '/' .. self.user .. '/' .. self.pass .. '/' .. stream_id end end return xc