summaryrefslogtreecommitdiffstats
path: root/TOOLS
diff options
context:
space:
mode:
authorChristoph Heinrich <christoph.heinrich@student.tugraz.at>2023-02-09 17:24:29 +0100
committerDudemanguy <random342@airmail.cc>2023-09-13 22:47:59 +0000
commit6714f6b820ddb526bd470a83351f4634699702c1 (patch)
tree08a3404135d65c5ea15715f98f7727bd93ca1c92 /TOOLS
parent662650bde319a57733bb4ea80f709a018d247f1d (diff)
downloadmpv-6714f6b820ddb526bd470a83351f4634699702c1.tar.bz2
mpv-6714f6b820ddb526bd470a83351f4634699702c1.tar.xz
TOOLS/lua/autoload: support directories
Adds support for adding directories to the playlist in addition to files. The propertiy `directory-mode` controls if directories get added. Recursive directory loading will get added in a later commit. Directories get sorted after files to behave the same way mpv behaves when it loads directories directly.
Diffstat (limited to 'TOOLS')
-rw-r--r--TOOLS/lua/autoload.lua30
1 files changed, 22 insertions, 8 deletions
diff --git a/TOOLS/lua/autoload.lua b/TOOLS/lua/autoload.lua
index 1e5f9df7f7..a7c7ede58a 100644
--- a/TOOLS/lua/autoload.lua
+++ b/TOOLS/lua/autoload.lua
@@ -122,6 +122,13 @@ table.filter = function(t, iter)
end
end
+table.append = function(t1, t2)
+ local t1_size = #t1
+ for i = 1, #t2 do
+ t1[t1_size + i] = t2[i]
+ end
+end
+
-- alphanum sorting for humans in Lua
-- http://notebook.kulchenko.com/algorithms/alphanumeric-natural-sorting-for-humans-in-lua
@@ -147,8 +154,7 @@ local autoloaded = nil
function get_playlist_filenames(playlist)
local filenames = {}
for i = 1, #playlist do
- local _, file = utils.split_path(playlist[i].filename)
- filenames[file] = true
+ filenames[playlist[i].filename] = true
end
return filenames
end
@@ -194,10 +200,13 @@ function find_and_add_entries()
utils.to_string(pl)))
local files = utils.readdir(dir, "files")
- if files == nil then
- msg.verbose("no other files in directory")
+ local load_dirs = mp.get_property("directory-mode") ~= "ignore"
+ local dirs = load_dirs and utils.readdir(dir, "dirs") or nil
+ if files == nil and dirs == nil then
+ msg.verbose("no other files or directories in directory")
return
end
+ files, dirs = files or {}, dirs or {}
table.filter(files, function (v, k)
-- The current file could be a hidden file, ignoring it doesn't load other
-- files from the current directory.
@@ -210,7 +219,12 @@ function find_and_add_entries()
end
return EXTENSIONS_TARGET[string.lower(ext)]
end)
+ table.filter(dirs, function(d)
+ return not ((o.ignore_hidden and string.match(d, "^%.")))
+ end)
alphanumsort(files)
+ alphanumsort(dirs)
+ table.append(files, dirs)
if dir == "." then
dir = ""
@@ -243,12 +257,12 @@ function find_and_add_entries()
-- skip files already in playlist
if not filenames[file] then
if direction == -1 then
- msg.info("Prepending " .. file)
- table.insert(append[-1], 1, {filepath, pos - 1})
+ msg.info("Prepending " .. filepath)
+ table.insert(append[-1], 1, {filepath, pl_current + i * direction + 1})
else
- msg.info("Adding " .. file)
+ msg.info("Adding " .. filepath)
if pl_count > 1 then
- table.insert(append[1], {filepath, pos - 1})
+ table.insert(append[1], {filepath, pl_current + i * direction - 1})
else
mp.commandv("loadfile", filepath, "append")
end