-- Copyright 2025 David Vazgenovich Shakaryan local util = require('util') local mp_options = require('mp.options') 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 config.scroll_margin = 4 config.click_timeout = 0.5 config.click_dbl_time = 0.3 config.click_max_drift = 2 config.btn_timeout = 1 config.bg_alpha = '44' config.bg_hover_alpha = '66' config.colour = { title = '999999', option = 'ffffff', option_dim = '999999', info = '666666', group = 'ffdd99', group_empty = '776644', selected = '00ff00', selected_empty = '337733', search_hl = 'ddff00', search_hl_empty = '778800', search_path = '666666', search_path_empty = '444444', icon_sorted = '4488cc', icon_playing = '3366ff', icon_favourite = 'ff00ff', icon_active = 'e68a00', icon_missing = 'ff0000', progress_bar_fg = '666666', progress_bar_bg = '333333', progress_bar_fg_active = 'e68a00', progress_bar_bg_active = '383838', scrollbar_fg = '666666', scrollbar_bg = '333333', scrollbar_fg_hover = '00cc00', scrollbar_bg_hover = '224422', status_info = '55bbdd', status_error = 'ff3333', menu_btn_fg = '000000', menu_btn_bg = '00cc00', bg_hover = '003300', } config.icon = { title = '»', cursor = '›', status = '🞸', playing = '\xe2\x8f\xba', active = '\xe2\x8f\xba', favourite = '★', missing = '!!!MISSING!!!', sorted = '⇅', menu_btn = '≡', } 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. 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') config.src_order = {} local conf_srcs = {} if f then for line in f:lines() do if #line > 0 then local k = line:match('^([^=]*)=') opts[k] = opts[k] or '' local src = k:match('^src%.([^.]*)%.') if src and not conf_srcs[src] then config.src_order[#config.src_order+1] = src conf_srcs[src] = true end 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 k = k:sub(#script_name + 2) opts[k] = opts[k] or '' end end mp_options.read_options(opts) util.unflatten_table(opts, config) local cli_srcs = {} for src in pairs(config.src or {}) do if not conf_srcs[src] then cli_srcs[#cli_srcs+1] = src end end table.sort(cli_srcs) for _, src in ipairs(cli_srcs) do config.src_order[#config.src_order+1] = src end return config