Skip to content

Commit de495d2

Browse files
Merge branch 'master' into new-defaults
2 parents a1392c8 + 050e717 commit de495d2

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

modules/playlist.lua

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ end
8888
---@diagnostic disable-next-line no-unknown
8989
local concurrent_loadlist_wrapper
9090

91-
---@alias ConcurrentRefMap table<List|Item,{directory: string, sublist: List}>
91+
---@alias ConcurrentRefMap table<List|Item,{directory: string?, sublist: List?, recurse: boolean?}>
9292

9393
---This function recursively loads directories concurrently in separate coroutines.
9494
---Results are saved in a tree of tables that allows asynchronous access.
@@ -100,6 +100,8 @@ local concurrent_loadlist_wrapper
100100
---@param refs ConcurrentRefMap
101101
---@return boolean?
102102
local function concurrent_loadlist_parse(directory, load_opts, prev_dirs, item_t, refs)
103+
if not refs[item_t] then refs[item_t] = {} end
104+
103105
--prevents infinite recursion from the item.path or opts.directory fields
104106
if prev_dirs[directory] then return end
105107
prev_dirs[directory] = true
@@ -110,22 +112,23 @@ local function concurrent_loadlist_parse(directory, load_opts, prev_dirs, item_t
110112
--if we can't parse the directory then append it and hope mpv fares better
111113
if list == nil then
112114
msg.warn("Could not parse", directory, "appending to playlist anyway")
113-
item_t.type = "file"
115+
refs[item_t].recurse = false
114116
return
115117
end
116118

117119
directory = list_opts.directory or directory
118-
if directory == "" then return end
119120

120121
--we must declare these before we start loading sublists otherwise the append thread will
121122
--need to wait until the whole list is loaded (when synchronous IO is used)
122123
refs[item_t].sublist = list or {}
123-
refs[list].directory = directory
124+
refs[list] = {directory = directory}
125+
126+
if directory == "" then return end
124127

125128
--launches new parse operations for directories, each in a different coroutine
126129
for _, item in ipairs(list) do
127130
if fb_utils.parseable_item(item) then
128-
fb_utils.coroutine.run(concurrent_loadlist_wrapper, fb_utils.get_new_directory(item, directory), load_opts, prev_dirs, item)
131+
fb_utils.coroutine.run(concurrent_loadlist_wrapper, fb_utils.get_new_directory(item, directory), load_opts, prev_dirs, item, refs)
129132
end
130133
end
131134
return true
@@ -167,11 +170,11 @@ local function concurrent_loadlist_append(list, load_opts, refs)
167170
if not g.sub_extensions[ fb_utils.get_extension(item.name, "") ]
168171
and not g.audio_extensions[ fb_utils.get_extension(item.name, "") ]
169172
then
170-
while (not refs[item].sublist and fb_utils.parseable_item(item)) do
173+
while fb_utils.parseable_item(item) and (not refs[item] or not refs[item].sublist) do
171174
coroutine.yield()
172175
end
173176

174-
if fb_utils.parseable_item(item) then
177+
if fb_utils.parseable_item(item) and refs[item] ~= false then
175178
concurrent_loadlist_append(refs[item].sublist, load_opts, refs)
176179
else
177180
loadfile(fb_utils.get_full_path(item, directory), load_opts, item.mpv_options)
@@ -233,12 +236,15 @@ local function loadlist(item, opts)
233236
opts.co = fb_utils.coroutine.assert()
234237
opts.concurrency = 0
235238

236-
local refs = setmetatable({}, {__mode = 'k'})
239+
---@type List
240+
local v_list = {item}
241+
---@type ConcurrentRefMap
242+
local refs = setmetatable({[v_list] = {directory = opts.directory}}, {__mode = 'k'})
237243

238244
--we need the current coroutine to suspend before we run the first parse operation, so
239245
--we schedule the coroutine to run on the mpv event queue
240246
fb_utils.coroutine.queue(concurrent_loadlist_wrapper, dir, opts, {}, item, refs)
241-
concurrent_loadlist_append({item, _directory = opts.directory}, opts, refs)
247+
concurrent_loadlist_append(v_list, opts, refs)
242248
else
243249
custom_loadlist_recursive(dir, opts, {})
244250
end

0 commit comments

Comments
 (0)