-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
root: an addon that allows users to specify complex custom roots
- Loading branch information
1 parent
ca49e81
commit 1be3031
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |