summaryrefslogtreecommitdiffstats
path: root/TOOLS
diff options
context:
space:
mode:
authordyphire <qimoge@gmail.com>2022-10-23 22:51:50 +0800
committerLeo Izen <leo.izen@gmail.com>2022-10-24 01:34:39 -0400
commit4bc6686b6a80bbae78febf97652e2f0841ca396a (patch)
tree94366a2180c18215248051711f6f3be932383646 /TOOLS
parent67260f8aac8dc894399cb8c94e384d1563c0dad4 (diff)
downloadmpv-4bc6686b6a80bbae78febf97652e2f0841ca396a.tar.bz2
mpv-4bc6686b6a80bbae78febf97652e2f0841ca396a.tar.xz
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
Diffstat (limited to 'TOOLS')
-rw-r--r--TOOLS/lua/autoload.lua23
1 files changed, 14 insertions, 9 deletions
diff --git a/TOOLS/lua/autoload.lua b/TOOLS/lua/autoload.lua
index 392ccdff37..048ecdedb0 100644
--- a/TOOLS/lua/autoload.lua
+++ b/TOOLS/lua/autoload.lua
@@ -127,6 +127,16 @@ end
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()
local path = mp.get_property("path", "")
local dir, filename = utils.split_path(path)
@@ -139,7 +149,7 @@ function find_and_add_entries()
return
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
if (pl_count > 1 and autoloaded == nil) or
(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)
local append = {[-1] = {}, [1] = {}}
+ local filenames = get_playlist_filenames()
for direction = -1, 1, 2 do -- 2 iterations, with direction = -1 and +1
for i = 1, MAXENTRIES do
local file = files[current + i * direction]
- local pl_e = pl[pl_current + i * direction]
if file == nil or file[1] == "." then
break
end
local filepath = dir .. file
- if pl_e then
- -- If there's a playlist entry, and it's the same file, stop.
- msg.trace(pl_e.filename.." == "..filepath.." ?")
- if pl_e.filename == filepath then
- break
- end
- end
+ -- skip files already in playlist
+ if filenames[file] then break end
if direction == -1 then
if pl_current == 1 then -- never add additional entries in the middle