Skip to content

Commit

Permalink
脚本更新
Browse files Browse the repository at this point in the history
  • Loading branch information
dyphire committed Dec 24, 2024
1 parent d2e5572 commit 32464e2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 28 deletions.
6 changes: 3 additions & 3 deletions scripts/file-browser/docs/addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down Expand Up @@ -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.

Expand Down
10 changes: 9 additions & 1 deletion scripts/file-browser/modules/ass.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions scripts/file-browser/modules/navigation/scanning.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion scripts/file-browser/modules/parsers/root.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function root_parser:parse()
return g.root, {
sorted = true,
filtered = true,
escaped = true,
}
end

Expand Down
14 changes: 7 additions & 7 deletions scripts/file-browser/modules/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 1 addition & 9 deletions scripts/sub-select.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 32464e2

Please sign in to comment.