diff options
Diffstat (limited to 'TOOLS/lua')
-rw-r--r-- | TOOLS/lua/acompressor.lua | 9 | ||||
-rw-r--r-- | TOOLS/lua/audio-hotplug-test.lua | 6 | ||||
-rw-r--r-- | TOOLS/lua/autocrop.lua | 2 | ||||
-rw-r--r-- | TOOLS/lua/autodeint.lua | 2 | ||||
-rw-r--r-- | TOOLS/lua/autoload.lua | 127 | ||||
-rw-r--r-- | TOOLS/lua/command-test.lua | 10 | ||||
-rw-r--r-- | TOOLS/lua/cycle-deinterlace-pullup.lua | 2 | ||||
-rw-r--r-- | TOOLS/lua/observe-all.lua | 8 | ||||
-rw-r--r-- | TOOLS/lua/ontop-playback.lua | 2 | ||||
-rw-r--r-- | TOOLS/lua/pause-when-minimize.lua | 2 | ||||
-rw-r--r-- | TOOLS/lua/skip-logo.lua | 18 | ||||
-rw-r--r-- | TOOLS/lua/status-line.lua | 2 | ||||
-rw-r--r-- | TOOLS/lua/test-hooks.lua | 4 |
13 files changed, 137 insertions, 57 deletions
diff --git a/TOOLS/lua/acompressor.lua b/TOOLS/lua/acompressor.lua index 6a6914076a..e94dc3e0fb 100644 --- a/TOOLS/lua/acompressor.lua +++ b/TOOLS/lua/acompressor.lua @@ -53,8 +53,10 @@ local params = { } local function parse_value(value) - -- Using nil here because tonumber differs between lua 5.1 and 5.2 when parsing fractions in combination with explicit base argument set to 10. - -- And we can't omit it because gsub returns 2 values which would get unpacked and cause more problems. Gotta love scripting languages. + -- Using nil here because tonumber differs between lua 5.1 and 5.2 when + -- parsing fractions in combination with explicit base argument set to 10. + -- And we can't omit it because gsub returns 2 values which would get + -- unpacked and cause more problems. Gotta love scripting languages. return tonumber(value:gsub('dB$', ''), nil) end @@ -76,7 +78,8 @@ local function show_osd(filter) for _,param in ipairs(params) do local value = parse_value(filter.params[param.name]) if not (param.hide_default and value == o['default_' .. param.name]) then - pretty[#pretty+1] = string.format('%s: %g%s', param.name:gsub("^%l", string.upper), value, param.dB) + pretty[#pretty+1] = string.format('%s: %g%s', param.name:gsub("^%l", string.upper), + value, param.dB) end end diff --git a/TOOLS/lua/audio-hotplug-test.lua b/TOOLS/lua/audio-hotplug-test.lua index 8dedc68cbe..e0ef223c0c 100644 --- a/TOOLS/lua/audio-hotplug-test.lua +++ b/TOOLS/lua/audio-hotplug-test.lua @@ -1,8 +1,6 @@ -local utils = require("mp.utils") - -mp.observe_property("audio-device-list", "native", function(name, val) +mp.observe_property("audio-device-list", "native", function(_, val) print("Audio device list changed:") - for index, e in ipairs(val) do + for _, e in ipairs(val) do print(" - '" .. e.name .. "' (" .. e.description .. ")") end end) diff --git a/TOOLS/lua/autocrop.lua b/TOOLS/lua/autocrop.lua index ea57d15658..eff659e50a 100644 --- a/TOOLS/lua/autocrop.lua +++ b/TOOLS/lua/autocrop.lua @@ -164,7 +164,7 @@ function detect_end() restore_hwdec() - local meta = {} + local meta -- Verify the existence of metadata. if cropdetect_metadata then diff --git a/TOOLS/lua/autodeint.lua b/TOOLS/lua/autodeint.lua index 4e929607a0..7615f52406 100644 --- a/TOOLS/lua/autodeint.lua +++ b/TOOLS/lua/autodeint.lua @@ -87,7 +87,7 @@ function stop_detect() timer = nil end -progressive, interlaced_tff, interlaced_bff, interlaced = 0, 1, 2, 3, 4 +progressive, interlaced_tff, interlaced_bff, interlaced = 0, 1, 2, 3 function judge(label) -- get the metadata diff --git a/TOOLS/lua/autoload.lua b/TOOLS/lua/autoload.lua index 7ec6924d31..486801e10d 100644 --- a/TOOLS/lua/autoload.lua +++ b/TOOLS/lua/autoload.lua @@ -10,6 +10,12 @@ 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/). +Option `ignore_patterns` is a comma-separated list of patterns (see lua.org/pil/20.2.html). +Additionally to the standard lua patterns, you can also escape commas with `%`, +for example, the option `bak%,x%,,another` will be resolved as patterns `bak,x,` and `another`. +But it does not mean you need to escape all lua patterns twice, +so the option `bak%%,%.mp4,` will be resolved as two patterns `bak%%` and `%.mp4`. + Example configuration would be: disabled=no @@ -22,6 +28,7 @@ additional_audio_exts=list,of,ext ignore_hidden=yes same_type=yes directory_mode=recursive +ignore_patterns=^~,^bak-,%.bak$ --]] @@ -42,7 +49,8 @@ o = { additional_audio_exts = "", ignore_hidden = true, same_type = false, - directory_mode = "auto" + directory_mode = "auto", + ignore_patterns = "" } options.read_options(o, nil, function(list) split_option_exts(list.additional_video_exts, list.additional_audio_exts, list.additional_image_exts) @@ -67,23 +75,59 @@ function SetUnion (a,b) return a end -function Split (s) +-- Returns first and last positions in string or past-to-end indices +function FindOrPastTheEnd (string, pattern, start_at) + local pos1, pos2 = string.find(string, pattern, start_at) + return pos1 or #string + 1, + pos2 or #string + 1 +end + +function Split (list) local set = {} - for v in string.gmatch(s, '([^,]+)') do set[v] = true end + + local item_pos = 1 + local item = "" + + while item_pos <= #list do + local pos1, pos2 = FindOrPastTheEnd(list, "%%*,", item_pos) + + local pattern_length = pos2 - pos1 + local is_comma_escaped = pattern_length % 2 + + local pos_before_escape = pos1 - 1 + local item_escape_count = pattern_length - is_comma_escaped + + item = item .. string.sub(list, item_pos, pos_before_escape + item_escape_count) + + if is_comma_escaped == 1 then + item = item .. "," + else + set[item] = true + item = "" + end + + item_pos = pos2 + 1 + end + + set[item] = true + + -- exclude empty items + set[""] = nil + return set end -EXTENSIONS_VIDEO = Set { +EXTENSIONS_VIDEO_DEFAULT = Set { '3g2', '3gp', 'avi', 'flv', 'm2ts', 'm4v', 'mj2', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'ogv', 'rmvb', 'webm', 'wmv', 'y4m' } -EXTENSIONS_AUDIO = Set { +EXTENSIONS_AUDIO_DEFAULT = Set { 'aiff', 'ape', 'au', 'flac', 'm4a', 'mka', 'mp3', 'oga', 'ogg', 'ogm', 'opus', 'wav', 'wma' } -EXTENSIONS_IMAGES = Set { +EXTENSIONS_IMAGES_DEFAULT = Set { 'avif', 'bmp', 'gif', 'j2k', 'jp2', 'jpeg', 'jpg', 'jxl', 'png', 'svg', 'tga', 'tif', 'tiff', 'webp' } @@ -95,11 +139,28 @@ function split_option_exts(video, audio, image) end split_option_exts(true, true, true) +function split_patterns() + o.ignore_patterns = Split(o.ignore_patterns) +end +split_patterns() + function create_extensions() EXTENSIONS = {} - if o.videos then SetUnion(SetUnion(EXTENSIONS, EXTENSIONS_VIDEO), o.additional_video_exts) end - if o.audio then SetUnion(SetUnion(EXTENSIONS, EXTENSIONS_AUDIO), o.additional_audio_exts) end - if o.images then SetUnion(SetUnion(EXTENSIONS, EXTENSIONS_IMAGES), o.additional_image_exts) end + EXTENSIONS_VIDEO = {} + EXTENSIONS_AUDIO = {} + EXTENSIONS_IMAGES = {} + if o.videos then + SetUnion(SetUnion(EXTENSIONS_VIDEO, EXTENSIONS_VIDEO_DEFAULT), o.additional_video_exts) + SetUnion(EXTENSIONS, EXTENSIONS_VIDEO) + end + if o.audio then + SetUnion(SetUnion(EXTENSIONS_AUDIO, EXTENSIONS_AUDIO_DEFAULT), o.additional_audio_exts) + SetUnion(EXTENSIONS, EXTENSIONS_AUDIO) + end + if o.images then + SetUnion(SetUnion(EXTENSIONS_IMAGES, EXTENSIONS_IMAGES_DEFAULT), o.additional_image_exts) + SetUnion(EXTENSIONS, EXTENSIONS_IMAGES) + end end create_extensions() @@ -127,19 +188,14 @@ function get_extension(path) end end -table.filter = function(t, iter) - for i = #t, 1, -1 do - if not iter(t[i]) then - table.remove(t, i) +function is_ignored(file) + for pattern, _ in pairs(o.ignore_patterns) do + if string.match(file, pattern) then + return true end end -end -table.append = function(t1, t2) - local t1_size = #t1 - for i = 1, #t2 do - t1[t1_size + i] = t2[i] - end + return false end -- alphanum sorting for humans in Lua @@ -174,19 +230,33 @@ function scan_dir(path, current_file, dir_mode, separator, dir_depth, total_file local files = utils.readdir(path, "files") or {} local dirs = dir_mode ~= "ignore" and utils.readdir(path, "dirs") or {} local prefix = path == "." and "" or path - table.filter(files, function (v) + + local filter = function(t, iter) + for i = #t, 1, -1 do + if not iter(t[i]) then + table.remove(t, i) + end + end + end + + 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 is_ignored(v) then return false end + local ext = get_extension(v) if ext == nil then return false end return extensions[string.lower(ext)] end) - table.filter(dirs, function(d) + filter(dirs, function(d) return not ((o.ignore_hidden and string.match(d, "^%."))) end) alphanumsort(files) @@ -196,7 +266,14 @@ function scan_dir(path, current_file, dir_mode, separator, dir_depth, total_file files[i] = prefix .. file end - table.append(total_files, files) + local append = function(t1, t2) + local t1_size = #t1 + for i = 1, #t2 do + t1[t1_size + i] = t2[i] + end + end + + append(total_files, files) if dir_mode == "recursive" then for _, dir in ipairs(dirs) do scan_dir(prefix .. dir .. separator, current_file, dir_mode, @@ -206,7 +283,7 @@ function scan_dir(path, current_file, dir_mode, separator, dir_depth, total_file for i, dir in ipairs(dirs) do dirs[i] = prefix .. dir end - table.append(total_files, dirs) + append(total_files, dirs) end end @@ -243,7 +320,7 @@ function find_and_add_entries() end end - local extensions = {} + local extensions if o.same_type then if EXTENSIONS_VIDEO[string.lower(this_ext)] ~= nil then extensions = EXTENSIONS_VIDEO diff --git a/TOOLS/lua/command-test.lua b/TOOLS/lua/command-test.lua index 877cacdeb6..a80edbd3e1 100644 --- a/TOOLS/lua/command-test.lua +++ b/TOOLS/lua/command-test.lua @@ -35,11 +35,11 @@ mp.observe_property("vo-configured", "bool", function(_, v) timer:resume() print("Slow screenshot command...") - res, err = mp.command_native({"screenshot"}) + res = mp.command_native({"screenshot"}) print("done, res: " .. utils.to_string(res)) print("Slow screenshot async command...") - res, err = mp.command_native_async({"screenshot"}, function(res) + res = mp.command_native_async({"screenshot"}, function(res) print("done (async), res: " .. utils.to_string(res)) timer:kill() end) @@ -78,13 +78,13 @@ mp.observe_property("vo-configured", "bool", function(_, v) mp.command_native_async({name = "subprocess", args = {"wc", "-c"}, stdin_data = "hello", capture_stdout = true}, - function(res, val, err) + function(_, val) print("Should be '5': " .. val.stdout) end) -- blocking stdin by default mp.command_native_async({name = "subprocess", args = {"cat"}, capture_stdout = true}, - function(res, val, err) + function(_, val) print("Should be 0: " .. #val.stdout) end) -- stdin + detached @@ -92,7 +92,7 @@ mp.observe_property("vo-configured", "bool", function(_, v) args = {"bash", "-c", "(sleep 5s ; cat)"}, stdin_data = "this should appear after 5s.\n", detach = true}, - function(res, val, err) + function(_, val) print("5s test: " .. val.status) end) diff --git a/TOOLS/lua/cycle-deinterlace-pullup.lua b/TOOLS/lua/cycle-deinterlace-pullup.lua index 2902e40dae..71ca00ac60 100644 --- a/TOOLS/lua/cycle-deinterlace-pullup.lua +++ b/TOOLS/lua/cycle-deinterlace-pullup.lua @@ -19,7 +19,7 @@ script_name = mp.get_script_name() pullup_label = string.format("%s-pullup", script_name) function pullup_on() - for i,vf in pairs(mp.get_property_native('vf')) do + for _, vf in pairs(mp.get_property_native('vf')) do if vf['label'] == pullup_label then return "yes" end diff --git a/TOOLS/lua/observe-all.lua b/TOOLS/lua/observe-all.lua index 0037439d5b..9d75692092 100644 --- a/TOOLS/lua/observe-all.lua +++ b/TOOLS/lua/observe-all.lua @@ -7,16 +7,16 @@ local utils = require("mp.utils") function observe(name) - mp.observe_property(name, "native", function(name, val) - print("property '" .. name .. "' changed to '" .. + mp.observe_property(name, "native", function(prop, val) + print("property '" .. prop .. "' changed to '" .. utils.to_string(val) .. "'") end) end -for i,name in ipairs(mp.get_property_native("property-list")) do +for _, name in ipairs(mp.get_property_native("property-list")) do observe(name) end -for i,name in ipairs(mp.get_property_native("options")) do +for _, name in ipairs(mp.get_property_native("options")) do observe("options/" .. name) end diff --git a/TOOLS/lua/ontop-playback.lua b/TOOLS/lua/ontop-playback.lua index b02716c4f1..27d4adef6c 100644 --- a/TOOLS/lua/ontop-playback.lua +++ b/TOOLS/lua/ontop-playback.lua @@ -3,7 +3,7 @@ local was_ontop = false -mp.observe_property("pause", "bool", function(name, value) +mp.observe_property("pause", "bool", function(_, value) local ontop = mp.get_property_native("ontop") if value then if ontop then diff --git a/TOOLS/lua/pause-when-minimize.lua b/TOOLS/lua/pause-when-minimize.lua index 99add709f1..33c29bb39b 100644 --- a/TOOLS/lua/pause-when-minimize.lua +++ b/TOOLS/lua/pause-when-minimize.lua @@ -4,7 +4,7 @@ local did_minimize = false -mp.observe_property("window-minimized", "bool", function(name, value) +mp.observe_property("window-minimized", "bool", function(_, value) local pause = mp.get_property_native("pause") if value == true then if pause == false then diff --git a/TOOLS/lua/skip-logo.lua b/TOOLS/lua/skip-logo.lua index ae66b22250..970cc288db 100644 --- a/TOOLS/lua/skip-logo.lua +++ b/TOOLS/lua/skip-logo.lua @@ -22,14 +22,14 @@ Example script-opts/skip-logo.conf: name = "black frame", -- print if matched skip = 10, -- number of seconds to skip forward score = 0.3, -- required score - fingerprint = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + fingerprint = string.rep("0", 512), }, { -- Skip ahead 20 seconds if a white frame was detected -- Note: this is dangerous non-sense. It's just for demonstration. name = "fun2", skip = 20, - fingerprint = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + fingerprint = string.rep("f", 512), }, } @@ -70,7 +70,6 @@ frames of a video. This could be fixed, but the author was too lazy to do so. --]] -local utils = require "mp.utils" local msg = require "mp.msg" local label = "skip-logo" @@ -121,8 +120,10 @@ end local function load_config() local conf_file = mp.find_config_file("script-opts/skip-logo.conf") local conf_fn - local err = nil + local err if conf_file then + -- luacheck: push + -- luacheck: ignore setfenv if setfenv then conf_fn, err = loadfile(conf_file) if conf_fn then @@ -131,12 +132,13 @@ local function load_config() else conf_fn, err = loadfile(conf_file, "t", config) end + -- luacheck: pop else err = "config file not found" end if conf_fn and (not err) then - local ok, err2 = pcall(conf_fn) + local _, err2 = pcall(conf_fn) err = err2 end @@ -146,7 +148,7 @@ local function load_config() if config.cases then for n, case in ipairs(config.cases) do - local err = nil + err = nil case.bitmap = hex_to_norm8(case.fingerprint) if case.bitmap == nil then err = "invalid or missing fingerprint field" @@ -241,7 +243,7 @@ mp.observe_property(meta_property, "native", function() read_frames() end) -mp.observe_property("seeking", "bool", function(name, val) +mp.observe_property("seeking", "bool", function(_, val) seeking = val if seeking == false then playback_start_pts = mp.get_property_number("playback-time") @@ -259,7 +261,7 @@ for _, f in ipairs(filters) do end if found then - mp.command(("no-osd vf add @%s:fingerprint"):format(label, filter)) + mp.command(("no-osd vf add @%s:fingerprint"):format(label)) else msg.warn("vf_fingerprint not found") end diff --git a/TOOLS/lua/status-line.lua b/TOOLS/lua/status-line.lua index e40dce234f..5b4510f42e 100644 --- a/TOOLS/lua/status-line.lua +++ b/TOOLS/lua/status-line.lua @@ -80,7 +80,7 @@ end timer = mp.add_periodic_timer(1, update_status_line) -function on_pause_change(name, value) +function on_pause_change(_, value) if value == false then timer:resume() else diff --git a/TOOLS/lua/test-hooks.lua b/TOOLS/lua/test-hooks.lua index 4e84d9e465..d91c3731bb 100644 --- a/TOOLS/lua/test-hooks.lua +++ b/TOOLS/lua/test-hooks.lua @@ -25,8 +25,8 @@ end local props = {"path", "metadata"} for _, name in ipairs(props) do - mp.observe_property(name, "native", function(name, val) - print("property '" .. name .. "' changed to '" .. + mp.observe_property(name, "native", function(prop, val) + print("property '" .. prop .. "' changed to '" .. utils.to_string(val) .. "'") end) end |