diff options
| -rw-r--r-- | catalogue.lua | 6 | ||||
| -rw-r--r-- | main.lua | 126 | ||||
| -rw-r--r-- | osd.lua | 2 | ||||
| -rw-r--r-- | util.lua | 8 |
4 files changed, 97 insertions, 45 deletions
diff --git a/catalogue.lua b/catalogue.lua index 7b83220..47a1b7a 100644 --- a/catalogue.lua +++ b/catalogue.lua @@ -95,15 +95,15 @@ function mt:load_xc_section(section) vv.group_type = 'series' vv.id = section.id .. ':series:' .. v.series_id vv.series_id = v.series_id - vv.image = util.strip(v.cover) + vv.image = util.strip_ne(v.cover) vv.lazy = true -- avoid API calls on search else vv.type = 'stream' vv.id = section.id .. ':stream:' .. v.stream_id vv.stream_type = v.stream_type vv.stream_id = v.stream_id - vv.image = util.strip(v.stream_icon) - vv.epg_channel_id = v.epg_channel_id + vv.image = util.strip_ne(v.stream_icon) + vv.epg_channel_id = util.strip_ne(v.epg_channel_id) end self:add(vv) @@ -364,29 +364,53 @@ local function series_group_menu_options(series) local season_num = tostring(season.season_number) if info.episodes and info.episodes[season_num] then for i, episode in pairs(info.episodes[season_num]) do - episodes[#episodes+1] = { + local epinfo = episode.info or {} + local t = { name = util.strip(episode.title), type = 'stream', stream_type = 'series', id = series.section .. ':stream:' .. episode.id, stream_id = episode.id, + image = util.strip_ne( + epinfo.movie_image), } + t.info_data = { + name = t.name, + cover = t.image, + description = epinfo.plot, + releasedate = epinfo.releasedate, + duration = epinfo.duration, + video = epinfo.video, + audio = epinfo.audio, + } + episodes[#episodes+1] = t end end local count = tostring(#episodes) - if season.episode_count then - count = count .. '/' .. season.episode_count + local tmp = util.strip_ne(season.episode_count) + if tmp then + count = count .. '/' .. tmp end - seasons[#seasons+1] = { + local t = { type = 'group', group_type = 'season', id = series.id .. ':season:' .. season.id, children = episodes, name = util.strip(season.name), info = count, + image = util.strip_ne(season.cover_big) or + util.strip_ne(season.cover), + } + t.info_data = { + name = t.name, + cover = t.image, + description = season.overview, + releasedate = season.air_date, + num_episodes = count, } + seasons[#seasons+1] = t end return seasons @@ -592,11 +616,10 @@ local function open_option_epg(opt) end local function add_info_field(dst, k, v, fmt) - if not v or v == '' then + local str = util.strip_ne(v) + if not str then return end - - local str = util.strip(tostring(v)) if fmt then str = string.format(fmt, str) end @@ -613,19 +636,28 @@ local function add_info_field(dst, k, v, fmt) end end +local function add_info_set(options, set) + if #set > 0 then + options[#options+1] = {name = ' '} + for _, v in ipairs(set) do + options[#options+1] = v + end + end +end + local function open_option_title_info(title, info) if not info or not info.info then return end - - info = info.info + local info = info.info local options = {} add_info_field(options, nil, info.name) add_info_field(options, 'Directed by', info.director) add_info_field(options, 'Starring', info.cast) - local desc = info.description or info.plot + local desc = util.strip_ne(info.description) or + util.strip_ne(info.plot) if desc then options[#options+1] = {name = ' '} for _, v in ipairs(util.wrap(desc, 80)) do @@ -633,31 +665,32 @@ local function open_option_title_info(title, info) end end - local set = {{name = ' '}} + local set = {} add_info_field(set, 'Genre', info.genre) - if info.releasedate then - local y, m, d = info.releasedate:match('(%d+)-(%d+)-(%d+)') + local date = util.strip_ne(info.releasedate) or + util.strip_ne(info.releaseDate) + if date then + local y, m, d = date:match('(%d+)-(%d+)-(%d+)') if y then local dt = {year = y, month = m, day = d} add_info_field(set, 'Release date', os.date('%d %B %Y', os.time(dt))) end end + add_info_field(set, 'Episode count', info.num_episodes) add_info_field(set, 'Running time', info.duration) - if #set > 1 then - for _, v in ipairs(set) do - options[#options+1] = v - end - end + add_info_set(options, set) - set = {{name = ' '}} + local set = {} if info.video then - if info.video.width and info.video.height then - local res = info.video.width .. 'x' .. - info.video.height - if info.video.display_aspect_ratio then - res = res .. ' (' .. - info.video.display_aspect_ratio .. ')' + local w = util.strip_ne(info.video.width) + local h = util.strip_ne(info.video.height) + if w and h then + local res = w .. 'x' .. h + local ar = util.strip_ne( + info.video.display_aspect_ratio) + if ar then + res = res .. ' (' .. ar .. ')' end add_info_field(set, 'Resolution', res) end @@ -669,21 +702,17 @@ local function open_option_title_info(title, info) if info.bitrate ~= 0 then add_info_field(set, 'Bitrate', info.bitrate, '%s Kbps') end - if #set > 1 then - for _, v in ipairs(set) do - options[#options+1] = v - end - end + add_info_set(options, set) - if info.youtube_trailer and info.youtube_trailer ~= '' then - local url = 'https://youtu.be/' .. info.youtube_trailer - options[#options+1] = {name = ' '} - options[#options+1] = { + local ytid = util.strip_ne(info.youtube_trailer) + if ytid then + local url = 'https://youtu.be/' .. ytid + add_info_set(options, {{ name = 'Trailer: ' .. url, type = 'stream', - id = 'youtube:' .. info.youtube_trailer, + id = 'youtube:' .. ytid, stream_url = url, - } + }}) end local m = { @@ -691,10 +720,9 @@ local function open_option_title_info(title, info) title = title, type = 'info', } - if info.cover_big and info.cover_big ~= '' then - m.img_url = info.cover_big - elseif info.cover and info.cover ~= '' then - m.img_url = info.cover + local img = util.strip_ne(info.cover_big) or util.strip_ne(info.cover) + if img then + m.img_url = img end push_menu(m) @@ -713,6 +741,18 @@ local function open_option_series_info(opt) xc:get_series_info(opt.series_id)) end +local function open_option_season_info(opt) + open_option_title_info( + 'Season Info: ' .. opt.name, + {info = opt.info_data}) +end + +local function open_option_episode_info(opt) + open_option_title_info( + 'Episode Info: ' .. opt.name, + {info = opt.info_data}) +end + local function open_option_info() local menu = menus[depth] local opt = menu.options[menu.cursor] @@ -726,7 +766,11 @@ local function open_option_info() open_option_epg(opt) elseif opt.group_type == 'series' then open_option_series_info(opt) - elseif opt.stream_id and opt.stream_type == 'movie' then + elseif opt.group_type == 'season' then + open_option_season_info(opt) + elseif opt.stream_type == 'series' then + open_option_episode_info(opt) + elseif opt.stream_type == 'movie' then open_option_movie_info(opt) end end @@ -308,7 +308,7 @@ function mt:redraw(menus, depth, favourites, playing_id) self:option_text(opt, info) .. self:option_path(opt, info) - if selected and opt.image and opt.image ~= '' then + if selected and opt.image then img = get_image_path(opt.image, true) end end @@ -22,6 +22,14 @@ function util.strip(str) return (str:gsub('^%s*(.-)%s*$', '%1')) end +function util.strip_ne(str) + if str == nil then + return nil + end + local str = util.strip(tostring(str)) + return str ~= '' and str or nil +end + -- skips over utf8 continuation bytes (10xxxxxx) -- valid positions range from 1 to #str + 1 (*after* the last byte) function util.utf8_seek(str, pos, n) |
