Recursion depth has been limited to 20, the same depth the demuxer uses.
Showing the changes to TOOLS/lua/autoload.lua (1 of 1 file). Show all
Unified · Split
| @@ -25,6 +25,7 @@ same_type=yes · 24 unmodified lines | |||
| 25 | --]] | 25 | --]] |
| 26 | 26 | ||
| 27 | MAXENTRIES = 5000 | 27 | MAXENTRIES = 5000 |
| 28 | MAXDIRSTACK = 20 | ||
| 28 | 29 | ||
| 29 | local msg = require 'mp.msg' | 30 | local msg = require 'mp.msg' |
| 30 | local options = require 'mp.options' | 31 | local options = require 'mp.options' |
| @@ -151,6 +152,51 @@ end · 120 unmodified lines | |||
| 151 | 152 | ||
| 152 | local autoloaded = nil | 153 | local autoloaded = nil |
| 153 | local added_entries = {} | 154 | local added_entries = {} |
| 155 | local autoloaded_dir = nil | ||
| 156 | |||
| 157 | function scan_dir(path, current_file, dir_mode, separator, dir_depth, total_files) | ||
| 158 | if dir_depth == MAXDIRSTACK then | ||
| 159 | return | ||
| 160 | end | ||
| 161 | msg.trace("scanning: " .. path) | ||
| 162 | local files = utils.readdir(path, "files") or {} | ||
| 163 | local dirs = dir_mode ~= "ignore" and utils.readdir(path, "dirs") or {} | ||
| 164 | local prefix = path == "." and "" or path | ||
| 165 | table.filter(files, function (v) | ||
| 166 | -- The current file could be a hidden file, ignoring it doesn't load other | ||
| 167 | -- files from the current directory. | ||
| 168 | if (o.ignore_hidden and not (prefix .. v == current_file) and string.match(v, "^%.")) then | ||
| 169 | return false | ||
| 170 | end | ||
| 171 | local ext = get_extension(v) | ||
| 172 | if ext == nil then | ||
| 173 | return false | ||
| 174 | end | ||
| 175 | return EXTENSIONS[string.lower(ext)] | ||
| 176 | end) | ||
| 177 | table.filter(dirs, function(d) | ||
| 178 | return not ((o.ignore_hidden and string.match(d, "^%."))) | ||
| 179 | end) | ||
| 180 | alphanumsort(files) | ||
| 181 | alphanumsort(dirs) | ||
| 182 | |||
| 183 | for i, file in ipairs(files) do | ||
| 184 | files[i] = prefix .. file | ||
| 185 | end | ||
| 186 | |||
| 187 | table.append(total_files, files) | ||
| 188 | if dir_mode == "recursive" then | ||
| 189 | for _, dir in ipairs(dirs) do | ||
| 190 | scan_dir(prefix .. dir .. separator, current_file, dir_mode, | ||
| 191 | separator, dir_depth + 1, total_files) | ||
| 192 | end | ||
| 193 | else | ||
| 194 | for i, dir in ipairs(dirs) do | ||
| 195 | dirs[i] = prefix .. dir | ||
| 196 | end | ||
| 197 | table.append(total_files, dirs) | ||
| 198 | end | ||
| 199 | end | ||
| 154 | 200 | ||
| 155 | function find_and_add_entries() | 201 | function find_and_add_entries() |
| 156 | local path = mp.get_property("path", "") | 202 | local path = mp.get_property("path", "") |
| @@ -174,6 +220,7 @@ function find_and_add_entries() · 17 unmodified lines | |||
| 174 | else | 220 | else |
| 175 | if pl_count == 1 then | 221 | if pl_count == 1 then |
| 176 | autoloaded = true | 222 | autoloaded = true |
| 223 | autoloaded_dir = dir | ||
| 177 | added_entries = {} | 224 | added_entries = {} |
| 178 | end | 225 | end |
| 179 | end | 226 | end |
| @@ -195,41 +242,22 @@ function find_and_add_entries() · 15 unmodified lines | |||
| 195 | msg.trace(("playlist-pos-1: %s, playlist: %s"):format(pl_current, | 242 | msg.trace(("playlist-pos-1: %s, playlist: %s"):format(pl_current, |
| 196 | utils.to_string(pl))) | 243 | utils.to_string(pl))) |
| 197 | 244 | ||
| 198 | local files = utils.readdir(dir, "files") | 245 | local files = {} |
| 199 | local load_dirs = mp.get_property("directory-mode") ~= "ignore" | 246 | do |
| 200 | local dirs = load_dirs and utils.readdir(dir, "dirs") or nil | 247 | local dir_mode = mp.get_property("directory-mode") |
| 201 | if files == nil and dirs == nil then | 248 | local separator = mp.get_property_native("platform") == "windows" and "\\" or "/" |
| 202 | msg.verbose("no other files or directories in directory") | 249 | scan_dir(autoloaded_dir, path, dir_mode, separator, 0, files) |
| 203 | return | ||
| 204 | end | 250 | end |
| 205 | files, dirs = files or {}, dirs or {} | ||
| 206 | table.filter(files, function (v, k) | ||
| 207 | -- The current file could be a hidden file, ignoring it doesn't load other | ||
| 208 | -- files from the current directory. | ||
| 209 | if (o.ignore_hidden and not (v == filename) and string.match(v, "^%.")) then | ||
| 210 | return false | ||
| 211 | end | ||
| 212 | local ext = get_extension(v) | ||
| 213 | if ext == nil then | ||
| 214 | return false | ||
| 215 | end | ||
| 216 | return EXTENSIONS_TARGET[string.lower(ext)] | ||
| 217 | end) | ||
| 218 | table.filter(dirs, function(d) | ||
| 219 | return not ((o.ignore_hidden and string.match(d, "^%."))) | ||
| 220 | end) | ||
| 221 | alphanumsort(files) | ||
| 222 | alphanumsort(dirs) | ||
| 223 | table.append(files, dirs) | ||
| 224 | 251 | ||
| 225 | if dir == "." then | 252 | if next(files) == nil then |
| 226 | dir = "" | 253 | msg.verbose("no other files or directories in directory") |
| 254 | return | ||
| 227 | end | 255 | end |
| 228 | 256 | ||
| 229 | -- Find the current pl entry (dir+"/"+filename) in the sorted dir list | 257 | -- Find the current pl entry (dir+"/"+filename) in the sorted dir list |
| 230 | local current | 258 | local current |
| 231 | for i = 1, #files do | 259 | for i = 1, #files do |
| 232 | if files[i] == filename then | 260 | if files[i] == path then |
| 233 | current = i | 261 | current = i |
| 234 | break | 262 | break |
| 235 | end | 263 | end |
| @@ -254,22 +282,21 @@ function find_and_add_entries() · 18 unmodified lines | |||
| 254 | break | 282 | break |
| 255 | end | 283 | end |
| 256 | 284 | ||
| 257 | local filepath = dir .. file | ||
| 258 | -- skip files that are/were already in the playlist | 285 | -- skip files that are/were already in the playlist |
| 259 | if not added_entries[filepath] then | 286 | if not added_entries[file] then |
| 260 | if direction == -1 then | 287 | if direction == -1 then |
| 261 | msg.info("Prepending " .. filepath) | 288 | msg.info("Prepending " .. file) |
| 262 | table.insert(append[-1], 1, {filepath, pl_current + i * direction + 1}) | 289 | table.insert(append[-1], 1, {file, pl_current + i * direction + 1}) |
| 263 | else | 290 | else |
| 264 | msg.info("Adding " .. filepath) | 291 | msg.info("Adding " .. file) |
| 265 | if pl_count > 1 then | 292 | if pl_count > 1 then |
| 266 | table.insert(append[1], {filepath, pl_current + i * direction - 1}) | 293 | table.insert(append[1], {file, pl_current + i * direction - 1}) |
| 267 | else | 294 | else |
| 268 | mp.commandv("loadfile", filepath, "append") | 295 | mp.commandv("loadfile", file, "append") |
| 269 | end | 296 | end |
| 270 | end | 297 | end |
| 271 | end | 298 | end |
| 272 | added_entries[filepath] = true | 299 | added_entries[file] = true |
| 273 | end | 300 | end |
| 274 | if pl_count == 1 and direction == -1 and #append[-1] > 0 then | 301 | if pl_count == 1 and direction == -1 and #append[-1] > 0 then |
| 275 | for i = 1, #append[-1] do | 302 | for i = 1, #append[-1] do |