summaryrefslogtreecommitdiff
path: root/config.lua
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-02-02 16:54:02 -0800
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-02-02 16:54:25 -0800
commit6cc548c27470b81114412f3ecd74380894eba72e (patch)
tree8f3417505cecc289da37e49b5bfc0eca92e20222 /config.lua
parent61dba9967975d4a48d33776449c627c11f9bd365 (diff)
downloadmpv-iptv-menu-6cc548c27470b81114412f3ecd74380894eba72e.tar.gz
mpv-iptv-menu-6cc548c27470b81114412f3ecd74380894eba72e.tar.xz
support specifying credentials via config file
Diffstat (limited to 'config.lua')
-rw-r--r--config.lua27
1 files changed, 25 insertions, 2 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)