Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
samhippo authored May 12, 2020
1 parent 2098c14 commit bf3c040
Showing 2 changed files with 59 additions and 31 deletions.
49 changes: 18 additions & 31 deletions load-dir-auto.lua
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions next-file.lua
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit bf3c040

Please sign in to comment.