From eb62d7ec40cbe07a6177e399071809dec85ab1f3 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Tue, 21 Apr 2015 18:30:52 +0200 Subject: TOOLS/autoload: load only files that make sense --- TOOLS/lua/autoload.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/TOOLS/lua/autoload.lua b/TOOLS/lua/autoload.lua index 4610a38589..0730397e75 100644 --- a/TOOLS/lua/autoload.lua +++ b/TOOLS/lua/autoload.lua @@ -7,6 +7,17 @@ -- Add at most 5 * 2 files when starting a file (before + after). MAXENTRIES = 5 +function Set (t) + local set = {} + for _, v in pairs(t) do set[v] = true end + return set +end + +EXTENSIONS = Set { + 'mkv', 'avi', 'mp4', 'ogv', 'webm', 'rmvb', 'flv', 'wmv', 'mpeg', 'mpg', 'm4v', '3gp', + 'mp3', 'wav', 'ogv', 'flac', 'm4a', 'wma', +} + mputils = require 'mp.utils' function add_files_at(index, files) @@ -18,6 +29,18 @@ function add_files_at(index, files) end end +function get_extension(path) + return string.match(path, "%.([^%.]+)$" ) +end + +table.filter = function(t, iter) + for i = #t, 1, -1 do + if not iter(t[i]) then + table.remove(t, i) + end + end +end + function find_and_add_entries() local path = mp.get_property("path", "") local dir, filename = mputils.split_path(path) @@ -29,6 +52,13 @@ function find_and_add_entries() if files == nil then return end + table.filter(files, function (v, k) + local ext = get_extension(v) + if ext == nil then + return false + end + return EXTENSIONS[string.lower(ext)] + end) table.sort(files, function (a, b) return string.lower(a) < string.lower(b) end) -- cgit v1.2.3