summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2025-05-20 09:14:12 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2025-05-20 09:14:12 -0700
commit55ade5ac655953bef1a7efeeb7fa91ec0fd47a77 (patch)
tree7b739c40eed2792ce87e60a6ae15fe0b1649352c
parent5df562dbadb762ee66a09fdd633a44d0fc1c1260 (diff)
downloadmpv-iptv-menu-55ade5ac655953bef1a7efeeb7fa91ec0fd47a77.tar.gz
mpv-iptv-menu-55ade5ac655953bef1a7efeeb7fa91ec0fd47a77.tar.xz
move XC code to a separate file
-rw-r--r--main.lua51
-rw-r--r--xc.lua54
2 files changed, 67 insertions, 38 deletions
diff --git a/main.lua b/main.lua
index 09b0936..1d2d252 100644
--- a/main.lua
+++ b/main.lua
@@ -1,5 +1,7 @@
-- Copyright 2025 David Vazgenovich Shakaryan
+local xclib = require('xc')
+
local utils = require('mp.utils')
-- font size is in units of osd height, which is scaled to 720
@@ -24,9 +26,11 @@ local colours = {
local script_name = mp.get_script_name()
local script_dir = mp.get_script_directory()
-local xc_server = mp.get_opt('iptv_menu.xc_server')
-local xc_user = mp.get_opt('iptv_menu.xc_user')
-local xc_pass = mp.get_opt('iptv_menu.xc_pass')
+local xc = xclib.new({
+ server = mp.get_opt('iptv_menu.xc_server'),
+ user = mp.get_opt('iptv_menu.xc_user'),
+ pass = mp.get_opt('iptv_menu.xc_pass'),
+})
local osd = mp.create_osd_overlay('ass-events')
local osd_width = 0
@@ -731,30 +735,8 @@ local function favourites_group_menu_options(group)
return options
end
-local function get_series_info(series_id)
- local cmd = 'curl -sSfL \'' .. xc_server .. '/player_api.php' ..
- '?username=' .. xc_user .. '&password=' .. xc_pass .. '&' ..
- 'action=get_series_info&series_id=' .. series_id .. '\''
- print('exec: ' .. cmd)
- local fd = io.popen(cmd)
- local json = fd:read('*all')
- fd:close()
- return utils.parse_json(json)
-end
-
-local function get_vod_info(vod_id)
- local cmd = 'curl -sSfL \'' .. xc_server .. '/player_api.php' ..
- '?username=' .. xc_user .. '&password=' .. xc_pass .. '&' ..
- 'action=get_vod_info&vod_id=' .. vod_id .. '\''
- print('exec: ' .. cmd)
- local fd = io.popen(cmd)
- local json = fd:read('*all')
- fd:close()
- return utils.parse_json(json)
-end
-
local function series_group_menu_options(series)
- local info = get_series_info(series.series_id)
+ local info = xc:get_series_info(series.series_id)
if not info or not info.seasons then
return {}
@@ -839,19 +821,12 @@ local function prev_menu()
end
local function play_stream(stream)
+ local url = stream.stream_url or
+ xc:stream_url(stream.stream_type, stream.stream_id)
+ if not url then return end
+
-- add a per-file option containing the stream id, allowing it to be
-- retrieved when a start-file event is received
- local url
- if stream.stream_url then
- url = stream.stream_url
- elseif stream.stream_type == 'series' then
- url = xc_server .. '/series/' .. xc_user .. '/' .. xc_pass ..
- '/' .. stream.stream_id .. '.vod'
- else
- url = xc_server .. '/' .. xc_user .. '/' .. xc_pass .. '/' ..
- stream.stream_id
- end
-
mp.commandv('loadfile', url, 'replace', -1,
'script-opt=iptv_menu.playing_id=' .. stream.id)
end
@@ -1018,7 +993,7 @@ local function add_info_field(dst, k, v, fmt)
end
local function open_option_movie_info(opt)
- local info = get_vod_info(opt.stream_id)
+ local info = xc:get_vod_info(opt.stream_id)
if not info or not info.info then
return
end
diff --git a/xc.lua b/xc.lua
new file mode 100644
index 0000000..fca88f7
--- /dev/null
+++ b/xc.lua
@@ -0,0 +1,54 @@
+-- Copyright 2025 David Vazgenovich Shakaryan
+
+local 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 cmd = 'curl -sSfL \'' .. self.server .. '/player_api.php' ..
+ '?username=' .. self.user .. '&password=' .. self.pass
+ for k, v in pairs(params) do
+ cmd = cmd .. '&' .. k .. '=' .. v
+ end
+ cmd = cmd .. '\''
+
+ print('exec: ' .. cmd)
+ local fd = io.popen(cmd)
+ local json = fd:read('*all')
+ fd:close()
+ return utils.parse_json(json)
+end
+
+function mt:get_series_info(id)
+ return self:get({action = 'get_series_info', series_id = id})
+end
+
+function mt:get_vod_info(id)
+ return self:get({action = 'get_vod_info', vod_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