rewrite favs sorting

lua's sort() doesn't save order of "equal" items
This commit is contained in:
wood 2020-01-22 18:08:55 +03:00
parent c8a0dd8c92
commit a4057f5033

View File

@ -215,8 +215,6 @@ local playlister = {
init = function(self) init = function(self)
if not self.pls then if not self.pls then
self.pls = mp.get_property_native("playlist") self.pls = mp.get_property_native("playlist")
pattern = ""
self.plsfiltered = tablekeys(self.pls)
end end
mp.commandv("stop") mp.commandv("stop")
--need to mark first entry non-current (mpv bug?) --need to mark first entry non-current (mpv bug?)
@ -224,10 +222,10 @@ local playlister = {
self.pls[1].current = false self.pls[1].current = false
end end
if favorites and #favorites>0 then if favorites and #favorites>0 then
table.sort(self.pls,function(i,j) return in_array(favorites,i.title) self:sortfavs()
and not in_array(favorites,j.title)
end)
end end
pattern = ""
self.plsfiltered = tablekeys(self.pls)
end, end,
show = function(self) show = function(self)
@ -275,6 +273,23 @@ local playlister = {
mp.osd_message(msg, osd_time) mp.osd_message(msg, osd_time)
end, end,
sortfavs = function(self)
--favorites bubbles to the top
local favs={}
local nonfavs={}
for _,v in ipairs(self.pls) do
if in_array(favorites,v.title) then
favs[#favs+1] = v
else
nonfavs[#nonfavs+1] = v
end
end
for i=1,#nonfavs do
favs[#favs+1] = nonfavs[i]
end
self.pls = favs
end,
filter = function(self) filter = function(self)
self.plsfiltered={} self.plsfiltered={}
for i,v in ipairs(self.pls) do for i,v in ipairs(self.pls) do