diff options
Diffstat (limited to 'main.lua')
| -rw-r--r-- | main.lua | 56 |
1 files changed, 24 insertions, 32 deletions
@@ -1,5 +1,6 @@ -- Copyright 2025 David Vazgenovich Shakaryan +local cacher = require('cacher') local util = require('util') local _catalogue = require('catalogue') local _downloader = require('downloader') @@ -37,6 +38,22 @@ local xc = _xc.new({ user = mp.get_opt('iptv_menu.xc_user'), pass = mp.get_opt('iptv_menu.xc_pass'), }) +xc = cacher.wrap(xc, { + directory = mp_utils.join_path(script_dir, 'cache'), + 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 osd = mp.create_osd_overlay('ass-events') local osd_width = 0 @@ -84,31 +101,6 @@ local function get_image_path(url, dl) end end -local function cached_xc_call(method, ...) - local id = xc.server:gsub('%W', '_') .. '.' .. method - if select('#', ...) ~= 0 then - id = id .. '.' .. table.concat({...}, '.') - end - - local path = mp_utils.join_path(script_dir, 'cache/' .. id) - local f = mp_utils.file_info(path) - local data - - if not f or os.time() - f.mtime > 24*60*60 then - data = xc[method](xc, ...) - if data then - util.write_json_file(path, data) - end - end - - if f and not data then - print('using cached ' .. id) - data = util.read_json_file(path) - end - - return data -end - local function load_data() local arr = { {id = 'live', name = 'Live TV', type = 'live'}, @@ -116,14 +108,14 @@ local function load_data() {id = 'series', name = 'Series', type = 'series'}, } for _, v in ipairs(arr) do - v.categories = cached_xc_call('get_' .. v.type .. '_categories') - v.elements = cached_xc_call( + v.categories = xc['get_' .. v.type .. '_categories'](xc) + v.elements = xc[ v.type == 'series' and 'get_series' or - ('get_' .. v.type .. '_streams')) + ('get_' .. v.type .. '_streams')](xc) end catalogue:load_xc_data(arr) - epg:load_xc_data(cached_xc_call('get_epg')) + epg:load_xc_data(xc:get_epg()) favourites = util.read_json_file( mp_utils.join_path(script_dir, 'favourites.json')) @@ -573,7 +565,7 @@ local function favourites_group_menu_options(group) end local function series_group_menu_options(series) - local info = cached_xc_call('get_series_info', series.series_id) + local info = xc:get_series_info(series.series_id) if not info or not info.seasons then return {} end @@ -922,13 +914,13 @@ end local function open_option_movie_info(opt) open_option_title_info( 'Movie Info: ' .. opt.name, - cached_xc_call('get_vod_info', opt.stream_id)) + xc:get_vod_info(opt.stream_id)) end local function open_option_series_info(opt) open_option_title_info( 'Series Info: ' .. opt.name, - cached_xc_call('get_series_info', opt.series_id)) + xc:get_series_info(opt.series_id)) end local function open_option_info() |
