TOOLS/lua/autoload: fix incorrect duplicate file loading behavior

This will correctly avoid the duplicate file loading when the playlist
changes due to shuffle playback or append new files.

Fixes https://github.com/mpv-player/mpv/issues/8575
This commit is contained in:
dyphire 2022-10-23 22:51:50 +08:00 committed by Leo Izen
parent 67260f8aac
commit 4bc6686b6a
No known key found for this signature in database
GPG Key ID: 5A71C331FD2FA19A
1 changed files with 14 additions and 9 deletions

View File

@ -127,6 +127,16 @@ end
local autoloaded = nil local autoloaded = nil
function get_playlist_filenames()
local filenames = {}
for n = 0, pl_count - 1, 1 do
local filename = mp.get_property('playlist/'..n..'/filename')
local _, file = utils.split_path(filename)
filenames[file] = true
end
return filenames
end
function find_and_add_entries() function find_and_add_entries()
local path = mp.get_property("path", "") local path = mp.get_property("path", "")
local dir, filename = utils.split_path(path) local dir, filename = utils.split_path(path)
@ -139,7 +149,7 @@ function find_and_add_entries()
return return
end end
local pl_count = mp.get_property_number("playlist-count", 1) pl_count = mp.get_property_number("playlist-count", 1)
-- check if this is a manually made playlist -- check if this is a manually made playlist
if (pl_count > 1 and autoloaded == nil) or if (pl_count > 1 and autoloaded == nil) or
(pl_count == 1 and EXTENSIONS[string.lower(get_extension(filename))] == nil) then (pl_count == 1 and EXTENSIONS[string.lower(get_extension(filename))] == nil) then
@ -191,22 +201,17 @@ function find_and_add_entries()
msg.trace("current file position in files: "..current) msg.trace("current file position in files: "..current)
local append = {[-1] = {}, [1] = {}} local append = {[-1] = {}, [1] = {}}
local filenames = get_playlist_filenames()
for direction = -1, 1, 2 do -- 2 iterations, with direction = -1 and +1 for direction = -1, 1, 2 do -- 2 iterations, with direction = -1 and +1
for i = 1, MAXENTRIES do for i = 1, MAXENTRIES do
local file = files[current + i * direction] local file = files[current + i * direction]
local pl_e = pl[pl_current + i * direction]
if file == nil or file[1] == "." then if file == nil or file[1] == "." then
break break
end end
local filepath = dir .. file local filepath = dir .. file
if pl_e then -- skip files already in playlist
-- If there's a playlist entry, and it's the same file, stop. if filenames[file] then break end
msg.trace(pl_e.filename.." == "..filepath.." ?")
if pl_e.filename == filepath then
break
end
end
if direction == -1 then if direction == -1 then
if pl_current == 1 then -- never add additional entries in the middle if pl_current == 1 then -- never add additional entries in the middle