diff options
author | oficsu <oficsu@gmail.com> | 2024-01-08 11:00:00 +0300 |
---|---|---|
committer | Kacper Michajłow <kasper93@gmail.com> | 2024-04-27 03:14:31 +0200 |
commit | 96b34148f1a11dc49901eee131e33cd7e1926834 (patch) | |
tree | 31a34548fed7c4059744ae73ec6534718abd36b5 /TOOLS | |
parent | 93708a9d3838d47da1ebffe846d4cbd5e07fab4a (diff) | |
download | mpv-96b34148f1a11dc49901eee131e33cd7e1926834.tar.bz2 mpv-96b34148f1a11dc49901eee131e33cd7e1926834.tar.xz |
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
Diffstat (limited to 'TOOLS')
-rw-r--r-- | TOOLS/lua/autoload.lua | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/TOOLS/lua/autoload.lua b/TOOLS/lua/autoload.lua index e0cfeb2997..eda05ad176 100644 --- a/TOOLS/lua/autoload.lua +++ b/TOOLS/lua/autoload.lua @@ -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 |