summaryrefslogtreecommitdiffstats
path: root/TOOLS
diff options
context:
space:
mode:
authorChristoph Heinrich <christoph.heinrich@student.tugraz.at>2023-02-13 17:14:51 +0100
committerDudemanguy <random342@airmail.cc>2023-09-13 22:47:59 +0000
commit5de1f5ad83f2da8a936fc5f0e349b11f167388e3 (patch)
treef6de0dc2f2c7905c2f104d63f73bd093d1203ef3 /TOOLS
parent6714f6b820ddb526bd470a83351f4634699702c1 (diff)
downloadmpv-5de1f5ad83f2da8a936fc5f0e349b11f167388e3.tar.bz2
mpv-5de1f5ad83f2da8a936fc5f0e349b11f167388e3.tar.xz
TOOLS/lua/autoload: avoid adding entries to the playlist more then once
Playlist entries should be added at most once, independent of if they got added by autoload or not.
Diffstat (limited to 'TOOLS')
-rw-r--r--TOOLS/lua/autoload.lua28
1 files changed, 15 insertions, 13 deletions
diff --git a/TOOLS/lua/autoload.lua b/TOOLS/lua/autoload.lua
index a7c7ede58a..ea2185b79c 100644
--- a/TOOLS/lua/autoload.lua
+++ b/TOOLS/lua/autoload.lua
@@ -150,14 +150,7 @@ function alphanumsort(filenames)
end
local autoloaded = nil
-
-function get_playlist_filenames(playlist)
- local filenames = {}
- for i = 1, #playlist do
- filenames[playlist[i].filename] = true
- end
- return filenames
-end
+local added_entries = {}
function find_and_add_entries()
local path = mp.get_property("path", "")
@@ -171,7 +164,7 @@ function find_and_add_entries()
return
end
- pl_count = mp.get_property_number("playlist-count", 1)
+ local pl_count = mp.get_property_number("playlist-count", 1)
this_ext = get_extension(filename)
-- check if this is a manually made playlist
if (pl_count > 1 and autoloaded == nil) or
@@ -179,7 +172,10 @@ function find_and_add_entries()
msg.verbose("stopping: manually made playlist")
return
else
- autoloaded = true
+ if pl_count == 1 then
+ autoloaded = true
+ added_entries = {}
+ end
end
if o.same_type then
@@ -243,8 +239,13 @@ function find_and_add_entries()
end
msg.trace("current file position in files: "..current)
+ -- treat already existing playlist entries, independent of how they got added
+ -- as if they got added by autoload
+ for _, entry in ipairs(pl) do
+ added_entries[entry.filename] = true
+ end
+
local append = {[-1] = {}, [1] = {}}
- local filenames = get_playlist_filenames(pl)
for direction = -1, 1, 2 do -- 2 iterations, with direction = -1 and +1
for i = 1, MAXENTRIES do
local pos = current + i * direction
@@ -254,8 +255,8 @@ function find_and_add_entries()
end
local filepath = dir .. file
- -- skip files already in playlist
- if not filenames[file] then
+ -- skip files that are/were already in the playlist
+ if not added_entries[filepath] then
if direction == -1 then
msg.info("Prepending " .. filepath)
table.insert(append[-1], 1, {filepath, pl_current + i * direction + 1})
@@ -268,6 +269,7 @@ function find_and_add_entries()
end
end
end
+ added_entries[filepath] = true
end
if pl_count == 1 and direction == -1 and #append[-1] > 0 then
for i = 1, #append[-1] do