1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
-- Copyright 2025 David Vazgenovich Shakaryan
local cacher = require('cacher')
local config = require('config')
local input = require('input')
local rt = require('rt')
local util = require('util')
local _catalogue = require('catalogue')
local _downloader = require('downloader')
local _epg = require('epg')
local _osd = require('osd')
local _state = require('state')
local _xc = require('xc')
local mp_utils = require('mp.utils')
local script_name = mp.get_script_name()
local state = _state.new()
local click_state = {}
local downloader = _downloader.new({limit = 5})
local xc = _xc.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'),
})
xc = cacher.wrap(xc, {
directory = config.cache_dir,
prefix = (xc.server:gsub('%W', '_')),
time = 24*60*60,
functions = {
get_live_categories = true,
get_live_streams = true,
get_vod_categories = true,
get_vod_streams = true,
get_vod_info = true,
get_series_categories = true,
get_series = true,
get_series_info = true,
get_epg = true,
},
})
local catalogue = _catalogue.new()
local epg = _epg.new()
local osd
local function dl_img(url, path, cb)
downloader:schedule(url, path, function(success, _, path)
if success then
cb(path)
else
osd:flash_error('Image download failed')
end
end)
end
osd = _osd.new({
img_path_func = function(url, cb)
local path = mp_utils.join_path(
config.img_dir, url:gsub('%W', '_'))
if not mp_utils.file_info(path) and cb then
dl_img(url, path, cb)
end
return path
end,
img_fail_cb = function()
osd:flash_error('Image load failed')
end
})
local ctx = {
catalogue = catalogue,
epg = epg,
xc = xc,
}
rt.init(state, osd, input, ctx)
mp.observe_property('mouse-pos', 'native', function(_, mpos)
input.update_mpos(mpos)
end)
mp.observe_property('user-data/osc/visibility', 'native', function(_, val)
if val and (osd:is_hidden() or val ~= 'never') then
state.saved_osc_visibility = val
end
end)
mp.observe_property('osd-dimensions', 'native', function(_, val)
osd:resize(val.w, val.h)
input.on_resize()
osd:redraw(state)
end)
mp.register_event('start-file', function()
state.playing_id = mp.get_opt('iptv_menu.playing_id')
osd:redraw(state)
end)
mp.register_event('end-file', function()
state.playing_id = nil
osd:redraw(state)
end)
mp.register_event('shutdown', function()
osd:destroy()
end)
state:push_menu({title = 'mpv-iptv-menu'})
state.saved_osc_visibility = mp.get_property_native(
'user-data/osc/visibility', 'auto')
rt.set_osc_visibility()
mp.add_forced_key_binding('TAB', 'toggle-menu', rt.toggle_menu)
input.init(state, osd)
input.set_key_mapping('MENU')
input.set_key_bindings()
mp.add_timeout(0, function()
rt.load_data()
state.depth = 0
rt.push_group_menu(catalogue:get('root'))
osd:redraw(state)
end)
|