1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-28 10:02:17 +00:00

TOOLS/lua/autoload: add ignore_pattern option

Autoload script can now exclude certain files

Why? Sometimes you want to ignore thumbnails,
auto-generated backups or just unwanted files

A non-exhaustive list of real-world examples:
- user backup files: '%.bak%.mp4$' or '^bak-'
- telegram-desktop thumbnails: '_thumb%.jpg$'
- a krita graphics editor backup suffix: '^~'

See documentation here: lua.org/pil/20.2.html
This commit is contained in:
oficsu 2024-01-08 11:00:00 +03:00 committed by Kacper Michajłow
parent 93708a9d38
commit 96b34148f1

View File

@ -10,6 +10,8 @@
To configure this script use file autoload.conf in directory script-opts (the "script-opts"
directory must be in the mpv configuration directory, typically ~/.config/mpv/).
See details of ignore_pattern format at lua.org/pil/20.2.html.
Example configuration would be:
disabled=no
@ -22,11 +24,13 @@ additional_audio_exts=list,of,ext
ignore_hidden=yes
same_type=yes
directory_mode=recursive
ignore_pattern=%.bak%.mp4$
--]]
MAXENTRIES = 5000
MAXDIRSTACK = 20
NEVERMATCHPATTERN = "$^"
local msg = require 'mp.msg'
local options = require 'mp.options'
@ -42,7 +46,8 @@ o = {
additional_audio_exts = "",
ignore_hidden = true,
same_type = false,
directory_mode = "auto"
directory_mode = "auto",
ignore_pattern = NEVERMATCHPATTERN
}
options.read_options(o, nil, function(list)
split_option_exts(list.additional_video_exts, list.additional_audio_exts, list.additional_image_exts)
@ -189,9 +194,14 @@ function scan_dir(path, current_file, dir_mode, separator, dir_depth, total_file
table.filter(files, function (v)
-- The current file could be a hidden file, ignoring it doesn't load other
-- files from the current directory.
if (o.ignore_hidden and not (prefix .. v == current_file) and string.match(v, "^%.")) then
local current = prefix .. v == current_file
if (o.ignore_hidden and not current and string.match(v, "^%.")) then
return false
end
if (not current and string.match(v, o.ignore_pattern)) then
return false;
end
local ext = get_extension(v)
if ext == nil then
return false