History

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

dyphire committed 4 years ago

Commit 4bc66861 parent 67260f81 file · +14 −9Browse files

Showing the changes to TOOLS/lua/autoload.lua (1 of 1 file). Show all

Unified · Split

TOOLS/lua/autoload.lua+14−9
@@ -127,6 +127,16 @@ end · 126 unmodified lines
127127
128128 local autoloaded = nil
129129
130+function get_playlist_filenames()
131+ local filenames = {}
132+ for n = 0, pl_count - 1, 1 do
133+ local filename = mp.get_property('playlist/'..n..'/filename')
134+ local _, file = utils.split_path(filename)
135+ filenames[file] = true
136+ end
137+ return filenames
138+end
139+
130140 function find_and_add_entries()
131141 local path = mp.get_property("path", "")
132142 local dir, filename = utils.split_path(path)
@@ -139,7 +149,7 @@ function find_and_add_entries() · 6 unmodified lines
139149 return
140150 end
141151
142− local pl_count = mp.get_property_number("playlist-count", 1)
152+ pl_count = mp.get_property_number("playlist-count", 1)
143153 -- check if this is a manually made playlist
144154 if (pl_count > 1 and autoloaded == nil) or
145155 (pl_count == 1 and EXTENSIONS[string.lower(get_extension(filename))] == nil) then
@@ -191,22 +201,17 @@ function find_and_add_entries() · 45 unmodified lines
191201 msg.trace("current file position in files: "..current)
192202
193203 local append = {[-1] = {}, [1] = {}}
204+ local filenames = get_playlist_filenames()
194205 for direction = -1, 1, 2 do -- 2 iterations, with direction = -1 and +1
195206 for i = 1, MAXENTRIES do
196207 local file = files[current + i * direction]
197− local pl_e = pl[pl_current + i * direction]
198208 if file == nil or file[1] == "." then
199209 break
200210 end
201211
202212 local filepath = dir .. file
203− if pl_e then
204− -- If there's a playlist entry, and it's the same file, stop.
205− msg.trace(pl_e.filename.." == "..filepath.." ?")
206− if pl_e.filename == filepath then
207− break
208− end
209− end
213+ -- skip files already in playlist
214+ if filenames[file] then break end
210215
211216 if direction == -1 then
212217 if pl_current == 1 then -- never add additional entries in the middle

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t