mirror of https://github.com/mpv-player/mpv
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:
parent
67260f8aac
commit
4bc6686b6a
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue