diff options
| author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2025-12-23 00:08:17 -0800 |
|---|---|---|
| committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2025-12-23 00:08:17 -0800 |
| commit | 12d340a5f7206c171c378f9fed73f9b73325c0c4 (patch) | |
| tree | fd0de4a92ef31f03052961dcedcce46ab12488a6 /main.lua | |
| parent | 67a9492bf2f7b6c42cc056b5ec0e3374ea4a78b0 (diff) | |
| download | mpv-iptv-menu-12d340a5f7206c171c378f9fed73f9b73325c0c4.tar.gz mpv-iptv-menu-12d340a5f7206c171c378f9fed73f9b73325c0c4.tar.xz | |
move EPG logic to separate file
Diffstat (limited to 'main.lua')
| -rw-r--r-- | main.lua | 66 |
1 files changed, 7 insertions, 59 deletions
@@ -2,6 +2,7 @@ local util = require('util') local _downloader = require('downloader') +local _epg = require('epg') local _xc = require('xc') local mp_utils = require('mp.utils') @@ -53,7 +54,7 @@ osd_bg.data = '{\\pos(0,0)}' .. colours.bg .. local osd_img local objects = {} -local epg = {} +local epg = _epg.new() local favourites local playing_id @@ -190,47 +191,6 @@ local function load_section(section, name, section_type) end end --- local (non-DST) offset from UTC -local tz_offset -do - local t = os.time() - tz_offset = os.time(os.date('*t', t)) - os.time(os.date('!*t', t)) -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} - return os.time(dt) + tz_offset - - (tonumber(zsign..zh) * 3600 + tonumber(zsign..zm) * 60) -end - -local function load_epg() - local tmp = cached_xc_call('get_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, - } - - if epg[ch] then - epg[ch][#epg[ch]+1] = prog - else - epg[ch] = {prog} - end - end - - for _, progs in pairs(epg) do - table.sort(progs, function(a, b) - return a.start < b.start - end) - end -end - local function load_data() add_object({ type = 'group', @@ -247,7 +207,7 @@ local function load_data() load_section('live', 'Live TV', 'live') load_section('movie', 'Movies', 'vod') load_section('series', 'Series', 'series') - load_epg() + epg:load_xc_data(cached_xc_call('get_epg')) favourites = util.read_json_file( mp_utils.join_path(script_dir, 'favourites.json')) @@ -624,22 +584,9 @@ local function toggle_menu_sort() update_osd() end -local function epg_programme(channel, time) - local progs = epg[channel] - if not progs then - return - end - - for _, v in ipairs(progs) do - if time >= v.start and time < v.stop then - return v - end - end -end - local function add_programme(opt, time) if opt.epg_channel_id then - local prog = epg_programme(opt.epg_channel_id, time) + local prog = epg:scheduled_programme(opt.epg_channel_id, time) if prog then opt.info = asscape(prog.title) end @@ -913,14 +860,15 @@ end local function open_option_epg(opt) local ch = opt.epg_channel_id:lower() - if not epg[ch] then + local progs = epg:channel_programmes(ch) + if not progs then return end local options = {} local curr = 0 local time = os.time() - for i, v in ipairs(epg[ch]) do + for i, v in ipairs(progs) do prog = { name = os.date('%a %d %b %H:%M', v.start) .. ' ' .. os.date('%H:%M', v.stop) .. ' ' .. v.title, |
