summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcin Kurczewski <mkurczew@gmail.com>2015-04-21 18:30:52 +0200
committerwm4 <wm4@nowhere>2015-04-21 20:24:00 +0200
commiteb62d7ec40cbe07a6177e399071809dec85ab1f3 (patch)
tree65c96e998e17cf016f5e3b95fce3209bfdb788ff
parenteabd2ac9e45849301c46af6b668215f4ab26aa98 (diff)
downloadmpv-eb62d7ec40cbe07a6177e399071809dec85ab1f3.tar.bz2
mpv-eb62d7ec40cbe07a6177e399071809dec85ab1f3.tar.xz
TOOLS/autoload: load only files that make sense
-rw-r--r--TOOLS/lua/autoload.lua30
1 files changed, 30 insertions, 0 deletions
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)