From 6cc548c27470b81114412f3ecd74380894eba72e Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 2 Feb 2026 16:54:02 -0800 Subject: support specifying credentials via config file --- config.lua | 27 +++++++++++++++++++++++++-- main.lua | 6 +++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/config.lua b/config.lua index 6708d83..805a47d 100644 --- a/config.lua +++ b/config.lua @@ -7,6 +7,9 @@ local mp_utils = require('mp.utils') local config = {} +local script_name = mp.get_script_name() +local script_dir = mp.get_script_directory() + -- font size is in units of osd height, which is scaled to 720 config.font_size = 20 @@ -65,14 +68,34 @@ config.icon = { menu_btn = '≡', } -local script_dir = mp.get_script_directory() config.tmp_dir = os.getenv('XDG_RUNTIME_DIR') or '/tmp' config.cache_dir = mp_utils.join_path(script_dir, 'cache') config.img_dir = mp_utils.join_path(script_dir, 'img') config.favourites_file = mp_utils.join_path(script_dir, 'favourites.json') --- flatten keys into `foo.bar.baz' form for script-opt overrides +-- flatten keys into `foo.bar.baz' form for script-opt overrides. unrecognised +-- keys are manually read and added to opts, as read_options only handles keys +-- with default values. local opts = util.flatten_table(config) +local f = io.open( + mp.command_native( + {'expand-path', '~~/script-opts/' .. script_name .. '.conf'}), + 'r') +if f then + for line in f:lines() do + if #line > 0 then + local k = line:match('^([^=]*)=') + opts[k] = opts[k] or '' + end + end + f:close() +end +for k, v in pairs(mp.get_property_native('script-opts')) do + if k:find(script_name .. '-', 1, true) == 1 then + local pk = k:sub(#script_name + 2) + opts[pk] = opts[pk] or '' + end +end mp_options.read_options(opts) util.unflatten_table(opts, config) diff --git a/main.lua b/main.lua index de6f4d3..090395d 100644 --- a/main.lua +++ b/main.lua @@ -19,9 +19,9 @@ local state = _state.new() local downloader = _downloader.new({limit = 5}) local xc = _xc.new({ - server = mp.get_opt('iptv_menu.xc_server'), - user = mp.get_opt('iptv_menu.xc_user'), - pass = mp.get_opt('iptv_menu.xc_pass'), + server = config.xc_server, + user = config.xc_user, + pass = config.xc_pass, }) xc = cacher.wrap(xc, { directory = config.cache_dir, -- cgit v1.2.3-70-g09d2