summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2025-12-22 11:11:19 -0800
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2025-12-22 11:11:19 -0800
commit304637102a306608d930b92d9422a85415ff9199 (patch)
tree7e1e2ef7b17ca41f4379506f5b42a67994c06b13 /main.lua
parent5b8d6951b91bfe6ce0da272e4623f9ba7eca2a57 (diff)
downloadmpv-iptv-menu-304637102a306608d930b92d9422a85415ff9199.tar.gz
mpv-iptv-menu-304637102a306608d930b92d9422a85415ff9199.tar.xz
consistent table formatting
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua272
1 files changed, 138 insertions, 134 deletions
diff --git a/main.lua b/main.lua
index c01226d..97faf62 100644
--- a/main.lua
+++ b/main.lua
@@ -9,21 +9,21 @@ local mp_utils = require('mp.utils')
-- font size is in units of osd height, which is scaled to 720
local font_size = 20
local colours = {
- bg='{\\alpha&H44&\\c&H&}',
- title='{\\c&999999&}',
- option='{\\c}',
- info='{\\c&666666&}',
- group='{\\c&H99DDFF&}',
- group_empty='{\\c&H446677&}',
- selected='{\\c&HFF00&}',
- selected_empty='{\\c&H337733&}',
- search_hl='{\\c&FFDD&}',
- search_hl_empty='{\\c&8877&}',
- search_path='{\\c&666666&}',
- search_path_empty='{\\c&444444&}',
- icon_playing='{\\c&HFF6633&}',
- icon_favourite='{\\c&HFF00FF&}',
- icon_active='{\\c&H99FF&}',
+ bg = '{\\alpha&H44&\\c&H&}',
+ title = '{\\c&999999&}',
+ option = '{\\c}',
+ info = '{\\c&666666&}',
+ group = '{\\c&H99DDFF&}',
+ group_empty = '{\\c&H446677&}',
+ selected = '{\\c&HFF00&}',
+ selected_empty = '{\\c&H337733&}',
+ search_hl = '{\\c&FFDD&}',
+ search_hl_empty = '{\\c&8877&}',
+ search_path = '{\\c&666666&}',
+ search_path_empty = '{\\c&444444&}',
+ icon_playing = '{\\c&HFF6633&}',
+ icon_favourite = '{\\c&HFF00FF&}',
+ icon_active = '{\\c&H99FF&}',
}
local script_name = mp.get_script_name()
@@ -99,13 +99,13 @@ local function add_object(obj)
obj.parent_id = obj.section .. ':category:catchall'
if not objects[obj.parent_id] then
add_object({
- section=obj.section,
- type='group',
- group_type='category',
- id=obj.parent_id,
- parent_id=obj.section .. ':category:0',
+ section = obj.section,
+ type = 'group',
+ group_type = 'category',
+ id = obj.parent_id,
+ parent_id = obj.section .. ':category:0',
-- non-ascii symbol to sort near end
- name='🞷CATCHALL🞷',
+ name = '🞷CATCHALL🞷',
})
end
end
@@ -138,23 +138,23 @@ end
local function load_section(section, name, section_type)
add_object({
- section=section,
- type='group',
- group_type='category',
- id=section .. ':category:0',
- parent_id='root',
- name=name,
+ section = section,
+ type = 'group',
+ group_type = 'category',
+ id = section .. ':category:0',
+ parent_id = 'root',
+ name = name,
})
local tmp = cached_xc_call('get_' .. section_type .. '_categories')
for _, v in ipairs(tmp) do
add_object({
- section=section,
- type='group',
- group_type='category',
- id=section .. ':category:' .. v.category_id,
- parent_id=section .. ':category:' .. v.parent_id,
- name=util.strip(v.category_name),
+ section = section,
+ type = 'group',
+ group_type = 'category',
+ id = section .. ':category:' .. v.category_id,
+ parent_id = section .. ':category:' .. v.parent_id,
+ name = util.strip(v.category_name),
})
end
@@ -163,9 +163,9 @@ local function load_section(section, name, section_type)
('get_' .. section_type .. '_streams'))
for _, v in ipairs(tmp) do
local vv = {
- section=section,
- parent_id=section .. ':category:' .. v.category_id,
- name=util.strip(v.name),
+ section = section,
+ parent_id = section .. ':category:' .. v.category_id,
+ name = util.strip(v.name),
}
if section_type == 'series' then
@@ -196,8 +196,9 @@ end
local function epg_parse_time(str)
local y, m, d, hh, mm, ss, zsign, zh, zm = str:match(
'(%d%d%d%d)(%d%d)(%d%d)(%d%d)(%d%d)(%d%d) ([+-])(%d%d)(%d%d)')
- local dt = {year=y, month=m, day=d, hour=hh, min=mm, sec=ss,
- isdst=false}
+ local dt = {
+ year = y, month = m, day = d,
+ hour = hh, min = mm, sec = ss, isdst = false}
return os.time(dt) + tz_offset -
(tonumber(zsign..zh) * 3600 + tonumber(zsign..zm) * 60)
end
@@ -207,10 +208,10 @@ local function load_epg()
for _, v in ipairs(tmp) do
local ch = v.channel:lower()
local prog = {
- start=epg_parse_time(v.start),
- stop=epg_parse_time(v.stop),
- title=v.title,
- desc=v.desc,
+ start = epg_parse_time(v.start),
+ stop = epg_parse_time(v.stop),
+ title = v.title,
+ desc = v.desc,
}
if epg[ch] then
@@ -229,15 +230,15 @@ end
local function load_data()
add_object({
- type='group',
- id='root',
+ type = 'group',
+ id = 'root',
})
add_object({
- type='group',
- id='favourites',
- parent_id='root',
- name='Favourites',
- lazy=true,
+ type = 'group',
+ id = 'favourites',
+ parent_id = 'root',
+ name = 'Favourites',
+ lazy = true,
})
load_section('live', 'Live TV', 'live')
@@ -250,7 +251,7 @@ local function load_data()
-- json loading/dumping breaks when the table is empty, so we need a
-- dummy value to prevent that
if next(favourites) == nil then
- favourites = {oi=true}
+ favourites = {oi = true}
end
end
@@ -417,18 +418,18 @@ local function update_osd_image(path, menu_res)
end
osd_img = {
- path=path,
- cmd={
- name='overlay-add',
- id=0,
- file='tmp.bgra',
- w=w,
- h=h,
- x=x,
- y=y,
- fmt='bgra',
- offset=0,
- stride=4*w,
+ path = path,
+ cmd = {
+ name = 'overlay-add',
+ id = 0,
+ file = 'tmp.bgra',
+ w = w,
+ h = h,
+ x = x,
+ y = y,
+ fmt = 'bgra',
+ offset = 0,
+ stride = 4*w,
},
}
@@ -438,12 +439,13 @@ local function update_osd_image(path, menu_res)
mp.command_native(osd_img.cmd)
end
else
- mp.command_native({name='overlay-remove', id=osd_img.cmd.id})
+ mp.command_native(
+ {name = 'overlay-remove', id = osd_img.cmd.id})
end
end
local function remove_osd_image()
- mp.command_native({name='overlay-remove', id=osd_img.cmd.id})
+ mp.command_native({name = 'overlay-remove', id = osd_img.cmd.id})
osd_img = nil
end
@@ -470,8 +472,8 @@ function update_osd()
local selected = i == menu.cursor and not menu.search_active
local info = {
- selected=selected,
- empty=(opt.type == 'group' and not opt.lazy and
+ selected = selected,
+ empty = (opt.type == 'group' and not opt.lazy and
#opt.children == 0),
}
out[#out+1] = osd_option_icons(opt, info) ..
@@ -540,17 +542,19 @@ local function cursor_end()
end
local function cursor_page_up()
- set_cursor(menus[depth].cursor - osd_menu_lines(), {keep_offset=true})
+ set_cursor(
+ menus[depth].cursor - osd_menu_lines(), {keep_offset = true})
end
local function cursor_page_down()
- set_cursor(menus[depth].cursor + osd_menu_lines(), {keep_offset=true})
+ set_cursor(
+ menus[depth].cursor + osd_menu_lines(), {keep_offset = true})
end
local function cursor_to_object(id)
for i, v in ipairs(menus[depth].options) do
if v.id == id then
- set_cursor(i, {centre=true})
+ set_cursor(i, {centre = true})
return
end
end
@@ -558,9 +562,9 @@ end
local function push_menu(t)
local menu = {
- options={},
- cursor=1,
- view_top=1,
+ options = {},
+ cursor = 1,
+ view_top = 1,
}
for k, v in pairs(t) do
@@ -694,8 +698,8 @@ local function favourites_group_menu_options(group)
-- display missing favourites so that they can be
-- removed
options[#options+1] = {
- id=id,
- name='🞷MISSING🞷 ' .. id,
+ id = id,
+ name = '🞷MISSING🞷 ' .. id,
}
end
end
@@ -715,12 +719,12 @@ local function series_group_menu_options(series)
if info.episodes and info.episodes[season_num] then
for i, episode in pairs(info.episodes[season_num]) do
episodes[#episodes+1] = {
- name=util.strip(episode.title),
- type='stream',
- stream_type='series',
- id=series.section .. ':stream:' ..
+ name = util.strip(episode.title),
+ type = 'stream',
+ stream_type = 'series',
+ id = series.section .. ':stream:' ..
episode.id,
- stream_id=episode.id,
+ stream_id = episode.id,
}
end
end
@@ -730,12 +734,12 @@ local function series_group_menu_options(series)
count = count .. '/' .. season.episode_count
end
seasons[#seasons+1] = {
- type='group',
- group_type='season',
- id=series.section .. 'series:season:' .. season.id,
- children=episodes,
- name=util.strip(season.name),
- info=count,
+ type = 'group',
+ group_type = 'season',
+ id = series.section .. 'series:season:' .. season.id,
+ children = episodes,
+ name = util.strip(season.name),
+ info = count,
}
end
@@ -767,10 +771,10 @@ end
local function push_group_menu(group)
push_menu({
- options=group_menu_options(group),
- title=group.name,
- type='group',
- group_id=group.id,
+ options = group_menu_options(group),
+ title = group.name,
+ type = 'group',
+ group_id = group.id,
})
update_osd()
end
@@ -884,22 +888,22 @@ end
local function open_epg_programme(prog)
local 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)},
+ {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=' '}
+ options[#options+1] = {name = ' '}
for _, v in ipairs(util.wrap(prog.desc, 80)) do
- options[#options+1] = {name=v}
+ options[#options+1] = {name = v}
end
end
push_menu({
- options=options,
- title='Programme: ' .. prog.title,
- type='epg',
+ options = options,
+ title = 'Programme: ' .. prog.title,
+ type = 'epg',
})
update_osd()
end
@@ -915,10 +919,10 @@ local function open_option_epg(opt)
local time = os.time()
for i, v in ipairs(epg[ch]) do
prog = {
- name=os.date('%a %d %b %H:%M', v.start) .. ' ' ..
+ name = os.date('%a %d %b %H:%M', v.start) .. ' ' ..
os.date('%H:%M', v.stop) .. ' ' .. v.title,
- info=v.desc,
- programme=v,
+ info = v.desc,
+ programme = v,
}
if curr == 0 and time >= v.start and time < v.stop then
@@ -930,11 +934,11 @@ local function open_option_epg(opt)
end
push_menu({
- options=options,
- title='EPG: ' .. opt.name .. ' (' .. ch .. ')',
- type='epg',
+ options = options,
+ title = 'EPG: ' .. opt.name .. ' (' .. ch .. ')',
+ type = 'epg',
})
- set_cursor(curr, {centre=true})
+ set_cursor(curr, {centre = true})
end
local function add_info_field(dst, k, v, fmt)
@@ -955,7 +959,7 @@ local function add_info_field(dst, k, v, fmt)
if i > 1 then
v = '\226\128\131\226\128\131' .. v
end
- dst[#dst+1] = {name=v}
+ dst[#dst+1] = {name = v}
end
end
@@ -973,18 +977,18 @@ local function open_option_movie_info(opt)
add_info_field(options, 'Starring', info.cast)
if info.description then
- options[#options+1] = {name=' '}
+ options[#options+1] = {name = ' '}
for _, v in ipairs(util.wrap(info.description, 80)) do
- options[#options+1] = {name=v}
+ options[#options+1] = {name = v}
end
end
- local set = {{name=' '}}
+ local set = {{name = ' '}}
add_info_field(set, 'Genre', info.genre)
if info.releasedate then
local y, m, d = info.releasedate:match('(%d+)-(%d+)-(%d+)')
if y then
- local dt = {year=y, month=m, day=d}
+ local dt = {year = y, month = m, day = d}
add_info_field(set, 'Release date',
os.date('%d %B %Y', os.time(dt)))
end
@@ -996,7 +1000,7 @@ local function open_option_movie_info(opt)
end
end
- set = {{name=' '}}
+ set = {{name = ' '}}
if info.video then
if info.video.width and info.video.height then
local res = info.video.width .. 'x' ..
@@ -1023,18 +1027,18 @@ local function open_option_movie_info(opt)
if info.youtube_trailer and info.youtube_trailer ~= '' then
local url = 'https://youtu.be/' .. info.youtube_trailer
- options[#options+1] = {name=' '}
+ options[#options+1] = {name = ' '}
options[#options+1] = {
- name='Trailer: ' .. url,
- type='stream',
- id='youtube:' .. info.youtube_trailer,
- stream_url=url,
+ name = 'Trailer: ' .. url,
+ type = 'stream',
+ id = 'youtube:' .. info.youtube_trailer,
+ stream_url = url,
}
end
local m = {
- options=options,
- title='Movie Info: ' .. opt.name,
+ options = options,
+ title = 'Movie Info: ' .. opt.name,
}
if info.cover_big and info.cover_big ~= '' then
m.img_url = info.cover_big
@@ -1130,7 +1134,7 @@ local function update_search_matches()
if not i then
break
end
- matches[#matches+1] = {start=i, stop=j}
+ matches[#matches+1] = {start = i, stop = j}
end
if #matches > 0 then
@@ -1228,13 +1232,13 @@ local function start_search()
update_osd()
else
push_menu({
- title='Searching: <text_with_cursor>' ..
+ title = 'Searching: <text_with_cursor>' ..
' <colours.info>(<num_matches>/<num_total>)',
- type='search',
- search_active=true,
- search_options=search_menu_options(menu.options),
- search_text='',
- search_cursor=1,
+ type = 'search',
+ search_active = true,
+ search_options = search_menu_options(menu.options),
+ search_text = '',
+ search_cursor = 1,
})
update_search_matches()
end
@@ -1276,16 +1280,16 @@ end
function bind_search_keys()
unbind_keys()
- bind_key('ANY_UNICODE', search_input_char, {complex=true})
- bind_key('BS', search_input_bs, {repeatable=true})
- bind_key('DEL', search_input_del, {repeatable=true})
+ bind_key('ANY_UNICODE', search_input_char, {complex = true})
+ bind_key('BS', search_input_bs, {repeatable = true})
+ bind_key('DEL', search_input_del, {repeatable = true})
bind_key('ENTER', end_search)
bind_key('ESC', cancel_search)
bind_key('Ctrl+c', cancel_search)
- bind_key('LEFT', search_cursor_left, {repeatable=true})
- bind_key('RIGHT', search_cursor_right, {repeatable=true})
+ bind_key('LEFT', search_cursor_left, {repeatable = true})
+ bind_key('RIGHT', search_cursor_right, {repeatable = true})
bind_key('Ctrl+a', search_cursor_start)
bind_key('Ctrl+e', search_cursor_end)
end
@@ -1303,12 +1307,12 @@ function bind_menu_keys()
bind_key('?', open_option_info)
bind_key('Ctrl+p', goto_playing)
- bind_key('UP', cursor_up, {repeatable=true})
- bind_key('DOWN', cursor_down, {repeatable=true})
+ bind_key('UP', cursor_up, {repeatable = true})
+ bind_key('DOWN', cursor_down, {repeatable = true})
bind_key('HOME', cursor_start)
bind_key('END', cursor_end)
- bind_key('PGUP', cursor_page_up, {repeatable=true})
- bind_key('PGDWN', cursor_page_down, {repeatable=true})
+ bind_key('PGUP', cursor_page_up, {repeatable = true})
+ bind_key('PGDWN', cursor_page_down, {repeatable = true})
end
local function toggle_menu()
@@ -1320,7 +1324,7 @@ local function toggle_menu()
if osd_img then
if osd.hidden then
mp.command_native(
- {name='overlay-remove', id=osd_img.cmd.id})
+ {name = 'overlay-remove', id = osd_img.cmd.id})
else
mp.command_native(osd_img.cmd)
end