summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua66
1 files changed, 62 insertions, 4 deletions
diff --git a/main.lua b/main.lua
index e9b48d2..a15c795 100644
--- a/main.lua
+++ b/main.lua
@@ -19,6 +19,7 @@ local colours = {
search_path_empty='{\\c&444444&}',
icon_playing='{\\c&HFF6633&}',
icon_favourite='{\\c&HFF00FF&}',
+ icon_active='{\\c&H99FF&}',
}
local script_dir = mp.get_script_directory()
@@ -82,6 +83,28 @@ local function utf8_seek(str, pos, n)
return pos
end
+-- returns table of strings wrapped at width. spaces are not removed, resulting
+-- in width-1 visible chars; newlines and end of string are handled similarly
+-- for consistency. words longer than width are not broken.
+local function wrap(str, width)
+ local t = {}
+ local start, stop = 0, 0
+ while stop < #str do
+ local i = str:find('[ \n]', stop + 1) or #str + 1
+ if i - start >= width then
+ t[#t+1] = str:sub(start, stop)
+ start = stop + 1
+ end
+ stop = i
+ if str:byte(stop) == 10 or stop >= #str then
+ t[#t+1] = str:sub(start, stop - 1) .. ' '
+ start = stop + 1
+ end
+ end
+
+ return t
+end
+
local function read_json_file(fn)
local f = io.open(script_dir .. '/' .. fn, 'r')
if not f then
@@ -280,6 +303,9 @@ local function osd_option_icons(opt, info)
if opt.id and favourites[opt.id] then
str = str .. colours.icon_favourite .. '★ '
end
+ if opt.active then
+ str = str .. colours.icon_active .. '\226\143\186 '
+ end
return str
end
@@ -641,10 +667,38 @@ local function goto_option()
update_osd()
end
+local function open_epg_programme(prog)
+ options = {
+ {name='Title: ' .. prog.title},
+ {name='Start: ' .. os.date('%a %d %b %H:%M', prog.start)},
+ {name='Stop: ' .. os.date('%a %d %b %H:%M', prog.stop)},
+ }
+
+ if prog.desc then
+ options[#options+1] = {name=' '}
+ for _, v in ipairs(wrap(prog.desc, 80)) do
+ options[#options+1] = {name=v}
+ end
+ end
+
+ push_menu({
+ options=options,
+ title='Programme: ' .. prog.title,
+ type='epg',
+ })
+ update_osd()
+end
+
local function open_option_epg()
local menu = menus[depth]
local opt = menu.options[menu.cursor]
- if not opt or not opt.epg_channel_id then
+ if not opt then
+ return
+ end
+
+ if menu.type == 'epg' and opt.programme then
+ return open_epg_programme(opt.programme)
+ elseif not opt.epg_channel_id then
return
end
@@ -657,21 +711,25 @@ local function open_option_epg()
local curr = 0
local time = os.time()
for i, v in ipairs(epg[ch]) do
- options[i] = {
+ prog = {
name=os.date('%a %d %b %H:%M', v.start) .. ' ' ..
os.date('%H:%M', v.stop) .. ' ' .. v.title,
info=v.desc,
+ programme=v,
}
-
if curr == 0 and time >= v.start and time < v.stop then
curr = i
+ prog.active = true
end
+
+ options[i] = prog
end
push_menu({
- title='EPG: ' .. opt.name .. ' (' .. ch .. ')',
options=options,
+ title='EPG: ' .. opt.name .. ' (' .. ch .. ')',
+ type='epg',
})
set_cursor(curr, {centre=true})
end