first commit
This commit is contained in:
44
mpv/scripts/file-browser/modules/parsers/file.lua
Normal file
44
mpv/scripts/file-browser/modules/parsers/file.lua
Normal file
@@ -0,0 +1,44 @@
|
||||
-- This file is an internal file-browser addon.
|
||||
-- It should not be imported like a normal module.
|
||||
|
||||
local msg = require 'mp.msg'
|
||||
local utils = require 'mp.utils'
|
||||
|
||||
--parser object for native filesystems
|
||||
local file_parser = {
|
||||
name = "file",
|
||||
priority = 110,
|
||||
api_version = '1.0.0',
|
||||
}
|
||||
|
||||
--try to parse any directory except for the root
|
||||
function file_parser:can_parse(directory)
|
||||
return directory ~= ''
|
||||
end
|
||||
|
||||
--scans the given directory using the mp.utils.readdir function
|
||||
function file_parser:parse(directory)
|
||||
local new_list = {}
|
||||
local list1 = utils.readdir(directory, 'dirs')
|
||||
if list1 == nil then return nil end
|
||||
|
||||
--sorts folders and formats them into the list of directories
|
||||
for i=1, #list1 do
|
||||
local item = list1[i]
|
||||
|
||||
msg.trace(item..'/')
|
||||
table.insert(new_list, {name = item..'/', type = 'dir'})
|
||||
end
|
||||
|
||||
--appends files to the list of directory items
|
||||
local list2 = utils.readdir(directory, 'files')
|
||||
for i=1, #list2 do
|
||||
local item = list2[i]
|
||||
|
||||
msg.trace(item)
|
||||
table.insert(new_list, {name = item, type = 'file'})
|
||||
end
|
||||
return new_list
|
||||
end
|
||||
|
||||
return file_parser
|
||||
25
mpv/scripts/file-browser/modules/parsers/root.lua
Normal file
25
mpv/scripts/file-browser/modules/parsers/root.lua
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
local g = require 'modules.globals'
|
||||
|
||||
--parser object for the root
|
||||
--not inserted to the parser list as it has special behaviour
|
||||
--it does get added to parsers under its ID to prevent confusing duplicates
|
||||
local root_parser = {
|
||||
name = "root",
|
||||
priority = math.huge,
|
||||
api_version = '1.0.0',
|
||||
}
|
||||
|
||||
function root_parser:can_parse(directory)
|
||||
return directory == ''
|
||||
end
|
||||
|
||||
--we return the root directory exactly as setup
|
||||
function root_parser:parse()
|
||||
return g.root, {
|
||||
sorted = true,
|
||||
filtered = true,
|
||||
}
|
||||
end
|
||||
|
||||
return root_parser
|
||||
Reference in New Issue
Block a user