From 32464e21f5d91c88d60ea35af27f1c511b7fd287 Mon Sep 17 00:00:00 2001 From: dyphire Date: Tue, 24 Dec 2024 18:55:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=84=9A=E6=9C=AC=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/file-browser/docs/addons.md | 6 +++--- scripts/file-browser/modules/ass.lua | 10 +++++++++- .../file-browser/modules/navigation/scanning.lua | 7 ------- scripts/file-browser/modules/parsers/root.lua | 1 - scripts/file-browser/modules/utils.lua | 14 +++++++------- scripts/sub-select.lua | 10 +--------- 6 files changed, 20 insertions(+), 28 deletions(-) diff --git a/scripts/file-browser/docs/addons.md b/scripts/file-browser/docs/addons.md index 3aae8cfd..f285887c 100644 --- a/scripts/file-browser/docs/addons.md +++ b/scripts/file-browser/docs/addons.md @@ -486,7 +486,7 @@ pattern. Any part of an input path that matches the pattern will be substituted the `directory` string. ```lua -fb.register_directory_mapping('/dev/dvd', '^dvd://.*') +fb.register_directory_mapping('/dev/dvd', '^dvd://.*', true) fb.resolve_directory_mapping('dvd://1') -- /dev/dvd ``` @@ -760,9 +760,9 @@ which treats paths with network protocols as absolute paths. Returns `str` with Lua special pattern characters escaped. -#### `fb_utils.resolve_directory_mapping(directory: string): string` +#### `fb_utils.resolve_directory_mapping(path: string): string` -Takes a `directory` string and resolves any +Takes a `path` string and resolves any [directory mappings](#fbregister_directory_mappingdirectory-string--nil-mapping-string-pattern-bool-void), replacing any substrings that match a mapping with the associated directory. diff --git a/scripts/file-browser/modules/ass.lua b/scripts/file-browser/modules/ass.lua index a0994cc3..0fc57911 100644 --- a/scripts/file-browser/modules/ass.lua +++ b/scripts/file-browser/modules/ass.lua @@ -44,17 +44,25 @@ end local function highlight_entry(v) if g.current_file.path == nil then return false end local full_path = fb_utils.get_full_path(v) + local alt_path = v.name and g.state.directory..v.name or nil if fb_utils.parseable_item(v) then return string.find(g.current_file.directory, full_path, 1, true) + or (alt_path and string.find(g.current_file.directory, alt_path, 1, true)) else return g.current_file.path == full_path + or (alt_path and g.current_file.path == alt_path) end end +local ass_cache = setmetatable({}, {__mode = 'k'}) + -- escape ass values and replace newlines local function ass_escape(str) - return fb_utils.ass_escape(str, true) + if ass_cache[str] then return ass_cache[str] end + local escaped = fb_utils.ass_escape(str, true) + ass_cache[str] = escaped + return escaped end --refreshes the ass text using the contents of the list diff --git a/scripts/file-browser/modules/navigation/scanning.lua b/scripts/file-browser/modules/navigation/scanning.lua index 33461c7f..02248c1d 100644 --- a/scripts/file-browser/modules/navigation/scanning.lua +++ b/scripts/file-browser/modules/navigation/scanning.lua @@ -124,13 +124,6 @@ local function update_list(moving_adjacent) g.state.list = list g.state.parser = opts.parser - --this only matters when displaying the list on the screen, so it doesn't need to be in the scan function - if not opts.escaped then - for i = 1, #list do - list[i].ass = list[i].ass or fb_utils.ass_escape(list[i].label or list[i].name, true) - end - end - --setting custom options from parsers g.state.directory_label = opts.directory_label g.state.empty_text = opts.empty_text or g.state.empty_text diff --git a/scripts/file-browser/modules/parsers/root.lua b/scripts/file-browser/modules/parsers/root.lua index 3e884fac..b99fa2e5 100644 --- a/scripts/file-browser/modules/parsers/root.lua +++ b/scripts/file-browser/modules/parsers/root.lua @@ -18,7 +18,6 @@ function root_parser:parse() return g.root, { sorted = true, filtered = true, - escaped = true, } end diff --git a/scripts/file-browser/modules/utils.lua b/scripts/file-browser/modules/utils.lua index cbe705a5..efd11d76 100644 --- a/scripts/file-browser/modules/utils.lua +++ b/scripts/file-browser/modules/utils.lua @@ -245,24 +245,24 @@ end -- Takes a directory string and resolves any directory mappings, -- returning the resolved directory. -function fb_utils.resolve_directory_mapping(directory) - if not directory then return directory end +function fb_utils.resolve_directory_mapping(path) + if not path then return path end for mapping, target in pairs(g.directory_mappings) do - local start, finish = string.find(directory, mapping) + local start, finish = string.find(path, mapping) if start then - msg.debug('mapping', mapping, 'found for directory', directory, 'changing to', target) + msg.debug('mapping', mapping, 'found for', path, 'changing to', target) -- if the mapping is an exact match then return the target as is - if finish == #directory then return target end + if finish == #path then return target end -- else make sure the path is correctly formatted target = fb_utils.fix_path(target, true) - return string.gsub(directory, mapping, target) + return string.gsub(path, mapping, target) end end - return directory + return path end --removes items and folders from the list diff --git a/scripts/sub-select.lua b/scripts/sub-select.lua index 9c60fb46..cef9ef85 100644 --- a/scripts/sub-select.lua +++ b/scripts/sub-select.lua @@ -198,7 +198,7 @@ end local function set_track(type, id) msg.verbose("setting", type, "to", id) if mp.get_property_number(type) == id then return end - mp.set_property(type, id) + mp.set_property('file-local-options/'..type, id) end --checks if the given audio matches the given track preference @@ -394,14 +394,6 @@ local function read_track_list() end end -local function reset_track_ids() - if not continue_script() then return end - mp.set_property('sid', 'auto') - if o.select_audio then mp.set_property('aid', 'auto') end -end - -mp.register_event("end-file", reset_track_ids) - --setup the audio and subtitle track lists when a new file is loaded mp.add_hook('on_preloaded', 25, read_track_list)