TOOLS/autoload: load only files that make sense

This commit is contained in:
Marcin Kurczewski 2015-04-21 18:30:52 +02:00 committed by wm4
parent eabd2ac9e4
commit eb62d7ec40
1 changed files with 30 additions and 0 deletions

View File

@ -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)