summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua51
1 files changed, 13 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