Skip to content

Commit

Permalink
root: an addon that allows users to specify complex custom roots
Browse files Browse the repository at this point in the history
  • Loading branch information
CogentRedTester committed Oct 14, 2022
1 parent ca49e81 commit 1be3031
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions addons/root.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
--[[
An addon that loads root items from a `~~/script-opts/file-browser-root.json` file.
The contents of this file will override the root script-opt.
The json file takes the form of a list array as defined by the addon API:
https://github.com/CogentRedTester/mpv-file-browser/blob/master/addons/addons.md#the-list-array
The main purpose of this addon is to allow for users to customise the appearance of their root items
using the label or ass fields:
[
{ "name": "Favourites/" },
{ "label": "~/", "name": "C:/Users/User/" },
{ "label": "1TB HDD", "name": "D:/" },
{ "ass": "{\\c&H007700&}Green Text", "name": "E:/" },
{ "label": "FTP Server", name: "ftp://user:[email protected]/" }
]
Make sure local directories always end with `/`.
`path` and `name` behave the same in the root but either name or label should have a value.
ASS styling codes: https://aegi.vmoe.info/docs/3.0/ASS_Tags/
]]

local mp = require 'mp'
local utils = require 'mp.utils'
local fb = require 'file-browser'

-- loads the root json file
local json_path = mp.command_native({'expand-path', '~~/script-opts/file-browser-root.json'})
local f = assert(io.open(json_path, "r"), 'failed to open '..json_path)
local root, err = utils.parse_json(f:read("*a"))
if not root then error(err) end

-- deletes any root values set by the root script-opt
local original_root = getmetatable(fb.get_root()).__original
for i in ipairs(original_root) do
original_root[i] = nil
end

local parser = {
version = '1.4.0',
priority = -math.huge
}

function parser:setup()
for i, v in ipairs(root) do
fb.register_root_item(v)
end
end

return parser

0 comments on commit 1be3031

Please sign in to comment.