diff --git a/load-dir-auto.lua b/load-dir-auto.lua index b99f92a..e0f92dd 100644 --- a/load-dir-auto.lua +++ b/load-dir-auto.lua @@ -1,4 +1,18 @@ 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 @@ -9,42 +23,15 @@ local function isNew(filename) return true end -local function isVideo(name) - local ext = string.match(name, "%.([^.]+)$") - if(ext == nil) then - return false - end - ext = ext:lower() - if( ext == "mkv" - or ext == "mp4" - or ext == "webm" - or ext == "wmv" - or ext == "avi" - or ext == "mpg" - or ext == "mpeg" - or ext == "mov" - or ext == "vob" - or ext == "ts" - or ext == "m2ts" - or ext == "divx" - or ext == "flv" - or ext == "asf" - or ext == "m4v" - or ext == "h264" - or ext == "rmvb" - or ext == "ogm") then - return true - else - return false - end -end - local function main() local dir, f = utils.split_path(mp.get_property("path")) local ar = utils.readdir(dir,"files") 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(isVideo(name) and isNew(filename)) then + if(valid[ext] and isNew(filename)) then mp.commandv('loadfile',filename,'append') end end diff --git a/next-file.lua b/next-file.lua new file mode 100644 index 0000000..56dece5 --- /dev/null +++ b/next-file.lua @@ -0,0 +1,41 @@ +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 getFileList() + local dir, f = utils.split_path(mp.get_property("path")) + local ar = utils.readdir(dir,"files") + local fileList = {} + for i, name in ipairs(ar) do + local ext = string.match(name, "%.([^.]+)$") + if(ext == nil) then ext = '' end + ext = string.lower(ext) + if(valid[ext]) then + table.insert(fileList,name) + end + end + return fileList +end + +local function main() + local fileList = getFileList() + for i = 1, #fileList do + if(mp.get_property("filename") == fileList[i]) then + local next = i + 1 + if(next > #fileList) then next = 1 end + local dir, f = utils.split_path(mp.get_property("path")) + mp.commandv('loadfile',utils.join_path(dir, fileList[next]),'replace') + return + end + end +end +mp.register_script_message("next-file", main) \ No newline at end of file