forked from samhippo/mpv-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload-dir.lua
44 lines (37 loc) · 1.25 KB
/
load-dir.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
local utils = require "mp.utils"
local ext = {
"mkv","mp4","webm","wmv","avi","3gp","ogv","mpg","mpeg","mov","vob" ,"ts","m2ts","divx","flv","asf","m4v","h264","h265","rmvb","rm","ogm"
,"jpg","jpeg","bmp","gif","png","svg","tif","tiff"
,"mp3","flac","ape","ogg","wav","wma","opus","tta","m4a","alac"
}
local valid = {}
for i = 1, #ext do
valid[ext[i]] = true
end
local function isNew(filename)
local playlist = mp.get_property_native('playlist')
for i = 1, #playlist do
if (playlist[i].filename == filename) then
return false
end
end
return true
end
local function main()
local dir, f = utils.split_path(mp.get_property("path"))
local ar = utils.readdir(dir,"files")
local c = 0
if(ar == nil) then return end
for i, name in ipairs(ar) do
local ext = string.match(name, "%.([^.]+)$")
if(ext == nil) then ext = '' end
ext = string.lower(ext)
local filename = utils.join_path(dir, name)
if(valid[ext] and isNew(filename)) then
mp.commandv('loadfile',filename,'append')
c = c + 1
end
end
mp.osd_message('Added '..c..' files')
end
mp.register_script_message("load-dir", main)