-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathplaylist-sort.lua
68 lines (61 loc) · 1.93 KB
/
playlist-sort.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
local utils = require "mp.utils"
local function getName()
local playlist = mp.get_property_native('playlist')
local dt = {}
for i = 1, #playlist do
table.insert(dt, {filename = playlist[i].filename, data = playlist[i].filename:lower()})
end
return dt
end
local function getDate()
local playlist = mp.get_property_native('playlist')
local dt = {}
for i = 1, #playlist do
local data = nil
local fi = utils.file_info(playlist[i].filename)
if(fi == nil) then data = 0 else data = fi.mtime end
table.insert(dt, {filename = playlist[i].filename, data = data})
end
return dt
end
local function getSize()
local playlist = mp.get_property_native('playlist')
local dt = {}
for i = 1, #playlist do
local data = nil
local fi = utils.file_info(playlist[i].filename)
if(fi == nil) then data = 0 else data = fi.size end
table.insert(dt, {filename = playlist[i].filename, data = data})
end
return dt
end
local function sort(dt,asc)
if(asc == nil or asc == "asc" or asc == "") then
table.sort(dt, function(a, b) return a.data < b.data end)
else
table.sort(dt, function(a, b) return a.data > b.data end)
end
end
local function main(type,asc)
local dt = nil
if(type == nil) then type = "name" end
if(asc == nil) then asc = "asc" end
if(type == "date") then
dt = getDate()
elseif(type == "size") then
dt = getSize()
else
dt = getName()
end
sort(dt,asc)
mp.commandv('playlist-clear')
for i,n in ipairs(dt) do
if(i == 1) then
mp.commandv('loadfile',n.filename,'replace')
else
mp.commandv('loadfile',n.filename,'append')
end
end
mp.osd_message("Playlist Sort: "..type.." "..asc)
end
mp.register_script_message("playlist-sort", main)