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
Unified · Split
| @@ -127,6 +127,16 @@ end · 126 unmodified lines | ||
| 127 | 127 | |
| 128 | 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 | 140 | function find_and_add_entries() |
| 131 | 141 | local path = mp.get_property("path", "") |
| 132 | 142 | local dir, filename = utils.split_path(path) |
| @@ -139,7 +149,7 @@ function find_and_add_entries() · 6 unmodified lines | ||
| 139 | 149 | return |
| 140 | 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 | 153 | -- check if this is a manually made playlist |
| 144 | 154 | if (pl_count > 1 and autoloaded == nil) or |
| 145 | 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 | 201 | msg.trace("current file position in files: "..current) |
| 192 | 202 | |
| 193 | 203 | local append = {[-1] = {}, [1] = {}} |
| 204 | + local filenames = get_playlist_filenames() | |
| 194 | 205 | for direction = -1, 1, 2 do -- 2 iterations, with direction = -1 and +1 |
| 195 | 206 | for i = 1, MAXENTRIES do |
| 196 | 207 | local file = files[current + i * direction] |
| 197 | − local pl_e = pl[pl_current + i * direction] | |
| 198 | 208 | if file == nil or file[1] == "." then |
| 199 | 209 | break |
| 200 | 210 | end |
| 201 | 211 | |
| 202 | 212 | 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 | |
| 210 | 215 | |
| 211 | 216 | if direction == -1 then |
| 212 | 217 | if pl_current == 1 then -- never add additional entries in the middle |