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
Showing the changes to TOOLS/lua/autoload.lua (1 of 1 file). Show all
Unified · Split
| @@ -127,6 +127,16 @@ end · 126 unmodified lines | |||
| 127 | 127 | ||
| 128 | local autoloaded = nil | 128 | local autoloaded = nil |
| 129 | 129 | ||
| 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 | |||
| 130 | function find_and_add_entries() | 140 | function find_and_add_entries() |
| 131 | local path = mp.get_property("path", "") | 141 | local path = mp.get_property("path", "") |
| 132 | local dir, filename = utils.split_path(path) | 142 | local dir, filename = utils.split_path(path) |
| @@ -139,7 +149,7 @@ function find_and_add_entries() · 6 unmodified lines | |||
| 139 | return | 149 | return |
| 140 | end | 150 | end |
| 141 | 151 | ||
| 142 | local pl_count = mp.get_property_number("playlist-count", 1) | 152 | pl_count = mp.get_property_number("playlist-count", 1) |
| 143 | -- check if this is a manually made playlist | 153 | -- check if this is a manually made playlist |
| 144 | if (pl_count > 1 and autoloaded == nil) or | 154 | if (pl_count > 1 and autoloaded == nil) or |
| 145 | (pl_count == 1 and EXTENSIONS[string.lower(get_extension(filename))] == nil) then | 155 | (pl_count == 1 and EXTENSIONS[string.lower(get_extension(filename))] == nil) then |
| @@ -191,22 +201,17 @@ function find_and_add_entries() · 45 unmodified lines | |||
| 191 | msg.trace("current file position in files: "..current) | 201 | msg.trace("current file position in files: "..current) |
| 192 | 202 | ||
| 193 | local append = {[-1] = {}, [1] = {}} | 203 | local append = {[-1] = {}, [1] = {}} |
| 204 | local filenames = get_playlist_filenames() | ||
| 194 | for direction = -1, 1, 2 do -- 2 iterations, with direction = -1 and +1 | 205 | for direction = -1, 1, 2 do -- 2 iterations, with direction = -1 and +1 |
| 195 | for i = 1, MAXENTRIES do | 206 | for i = 1, MAXENTRIES do |
| 196 | local file = files[current + i * direction] | 207 | local file = files[current + i * direction] |
| 197 | local pl_e = pl[pl_current + i * direction] | ||
| 198 | if file == nil or file[1] == "." then | 208 | if file == nil or file[1] == "." then |
| 199 | break | 209 | break |
| 200 | end | 210 | end |
| 201 | 211 | ||
| 202 | local filepath = dir .. file | 212 | local filepath = dir .. file |
| 203 | if pl_e then | 213 | -- skip files already in playlist |
| 204 | -- If there's a playlist entry, and it's the same file, stop. | 214 | if filenames[file] then break end |
| 205 | msg.trace(pl_e.filename.." == "..filepath.." ?") | ||
| 206 | if pl_e.filename == filepath then | ||
| 207 | break | ||
| 208 | end | ||
| 209 | end | ||
| 210 | 215 | ||
| 211 | if direction == -1 then | 216 | if direction == -1 then |
| 212 | if pl_current == 1 then -- never add additional entries in the middle | 217 | if pl_current == 1 then -- never add additional entries in the middle |