### Basic Parser Setup with file-browser API Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Shows the minimal structure for an addon parser: loading the file-browser module, defining a parser table with a priority, and registering a root item in the setup method. ```lua local fb = require "file-browser" local parser = { priority = 100, } function parser:setup() fb.register_root_item("Example/") end return parser ``` -------------------------------- ### Single command keybind example Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/custom-keybinds.md Defines a keybind for KP1 that sends a single print-text command. The command is a JSON array of arguments. This example shows the basic structure of a keybind object. ```json { "key": "KP1", "command": ["print-text", "example"], } ``` -------------------------------- ### fb.iterate_opt example Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Iterates over a comma-separated options string using the root_separators from file_browser.conf. The example prints each item in the list, demonstrating the iterator returned by fb.iterate_opt. ```lua local opt = "a,b,zz z" -- root_separators=, for item in fb.iterate_opt(opt) do print(item) -- prints: 'a', 'b', 'zz z' end ``` -------------------------------- ### Parser API Usage with insert_root_item Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Demonstrates the parser-specific API where methods are available on the parser object after loading. Shows that calling insert_root_item outside setup fails because the API is not yet attached. ```lua local parser = { priority = 100, } function parser:setup() -- same operations self.insert_root_item({ name = "Example/", type = "dir" }) parser.insert_root_item({ name = "Example/", type = "dir" }) end -- will not work since the API hasn't been added to the parser yet parser.insert_root_item({ name = "Example/", type = "dir" }) return parser ``` -------------------------------- ### Multiple commands keybind example Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/custom-keybinds.md Defines a keybind for KP2 that sends two commands sequentially: print-text and show-text. The command field is an array of arrays, each inner array being a separate command. ```json { "key": "KP2", "command": [ ["print-text", "example2"], ["show-text", "example2"] ] } ``` -------------------------------- ### Directory Mapping Registration and Resolution Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Shows how to register a directory mapping with a Lua pattern and resolve it. The example maps 'dvd://' paths to '/dev/dvd' and resolves 'dvd://1' to '/dev/dvd/1'. ```lua fb.register_directory_mapping('/dev/dvd', '^dvd://.*', true) fb.resolve_directory_mapping('dvd://1') -- /dev/dvd ``` -------------------------------- ### Create a basic file-browser addon parser Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Minimal addon that returns a parser table. Must define api_version, priority, and can_parse/parse methods. The name field is optional and defaults to the filename; duplicate names get numeric suffixes. ```lua local parser = { api_version = '1.0.0', priority = 100, name = "example" -- this parser will have the id 'example' or 'example_#' if there are duplicates } function parser:can_parse(directory) return directory == "Example/" end function parser:parse(directory, state) local list, opts ------------------------------ --- populate the list here --- ------------------------------ return list, opts end return parser ``` -------------------------------- ### Example command to add an audio track using %f Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/custom-keybinds.md Shows a JSON keybind configuration that adds an audio track using the selected file's path. The %f code is replaced with the filepath of the selected item. This command will not run if no item is selected. ```json { "key": "Ctrl+a", "command": ["audio-add", "%f"], "filter": "file" } ``` -------------------------------- ### Parser filter example Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/custom-keybinds.md Shows a keybind with a parser filter set to 'ftp file', meaning the command only runs in directories loaded by the 'ftp' or 'file' parsers. The parser names are separated by spaces. ```json { "key": "KP2", "command": [ ["print-text", "example3"] ], "parser": "ftp file" } ``` -------------------------------- ### Repeatable keybind with flags example Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/custom-keybinds.md Defines a keybind for the 'p' key that is repeatable by setting the flags field to {"repeatable": true}. This allows holding the key to repeat the command. ```json { "key": "p", "command": ["print-text", "spam-text"], "flags": { "repeatable": true } } ``` -------------------------------- ### Delayed command with `delay-command` Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/custom-keybinds.md Delays the following command by the specified number of seconds. This example sends `print-text` after 5 seconds. ```json { "key": "KP1", "command": ["script-message", "delay-command", "5", "print-text", "example"], } ``` -------------------------------- ### fb.add_default_extension(ext: string): void Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Adds an extension to the default extension filter whitelist. Can only be called inside the setup() method. ```APIDOC ## fb.add_default_extension(ext: string): void ### Description Adds the given extension to the default extension filter whitelist. This function can only be called inside the `setup()` method. ### Method N/A (function) ### Endpoint N/A ### Parameters - **ext** (string) - Required - The file extension to add to the whitelist. ### Response No return value. ``` -------------------------------- ### Restrict delete_files to /tmp/ and return false for passthrough Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Extends the delete_files example to only allow deletion when the current directory is /tmp/. If the directory is different, the function returns false to let the keybind handler run the next priority command. Any other return value (including nil) is treated as success. ```lua local fb = require "file-browser" -- see #api-functions and #utility-functions local function main(keybind, state, co) if state.directory ~= "/tmp/" then return false end for index, item in state.list do if state.selection[index] and item.type == "file" then os.remove( fb.get_full_path(item, state.directory) ) end end end parser.keybinds = { { "Alt+DEL", "delete_files", main, {} }, } ``` -------------------------------- ### fb.evaluate_string usage examples Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Shows how to use fb.evaluate_string to evaluate Lua expressions and chunks. The first two lines evaluate simple expressions, while the last two evaluate a multi-line chunk with a custom environment. Note that the final example fails because the default globals are not available when defaults is false. ```lua fb.evaluate_string('return 5 + 5') -- 10 fb.evaluate_string('x = 20 ; return x * x') -- 400 local code = [[ local arr = {1, 2, 3, 4} table.insert(arr, x) return unpack(arr) ]] fb.evaluate_string(code, 'test3', {x = 5}) -- 1, 2, 3, 4, 5 fb.evaluate_string(code, 'test4', nil, false) -- Lua error: [string "test4"]:2: attempt to index global 'table' (a nil value) ``` -------------------------------- ### Addon Parser Table Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md An addon must return a parser table or an array of parser tables. Each parser must contain the required members: priority, api_version, can_parse, and parse. Optional members include name, keybind_name, setup, and keybinds. ```APIDOC ## Addon Parser Table ### Description An addon must return a parser table or an array of parser tables. Each parser must contain the required members: priority, api_version, can_parse, and parse. Optional members include name, keybind_name, setup, and keybinds. ### Required Members - **priority** (number) - Required - A number to determine what order parsers are tested. - **api_version** (string) - Required - The API version the parser is using. - **can_parse** (method) - Required - Arguments: string, parse_state_table. Returns boolean indicating whether the given path is compatible with the parser. - **parse** (method) - Required - Arguments: string, parse_state_table. Returns list_table and opts_table. ### Optional Members - **name** (string) - Optional - The name of the parser used for debug messages and to create a unique id. Defaults to the filename with `.lua` or `-browser.lua` removed. - **keybind_name** (string) - Optional - The name to use when setting custom keybind filters. Defaults to the value of name. - **setup** (method) - Optional - Automatically run after all parsers are imported and API functions are made available. - **keybinds** (table) - Optional - An array of keybind objects for the browser to set when loading. ### Example ```lua local parser = { api_version = '1.0.0', priority = 100, name = "example" -- this parser will have the id 'example' or 'example_#' if there are duplicates } function parser:can_parse(directory) return directory == "Example/" end function parser:parse(directory, state) local list, opts ------------------------------ --- populate the list here --- ------------------------------ return list, opts end return parser ``` ``` -------------------------------- ### parse() Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md The parse method is called by the browser to get a list of items for a directory. It runs in a Lua coroutine and can yield for asynchronous operations. It returns a list array of item tables. ```APIDOC ## parse() ### Description Called by the browser to retrieve a list of items for a given directory. Runs in a Lua coroutine, allowing asynchronous operations. Returns a list array of item tables. ### Method parse(directory, state) ### Parameters - **directory** (string) - Required - The directory path to parse. - **state** (table) - Required - The state table containing methods like yield() and is_coroutine_current(). ### Returns - **list** (array of item tables) - The list of items in the directory. ### Example ```lua function parser:parse(directory, state) local list = { { name = "first/", type = "dir" }, { name = "second/", type = "dir" }, { name = "third/", type = "dir" }, { name = "file%01", type = "file", label = "file1" }, { name = "file2", type = "file", path = "https://youtube.com/video" }, } return list end ``` ``` -------------------------------- ### Override default scroll keybinds with script-binding Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/custom-keybinds.md Shows how to change the default scroll keybinds (UP/DOWN) to use the scroll wheel by binding WHEEL_UP and WHEEL_DOWN to the dynamic scroll_up and scroll_down keybinds. The example also rebinds UP/DOWN to volume controls. ```json [ { "key": "WHEEL_UP", "command": ["script-binding", "file_browser/dynamic/scroll_up"] }, { "key": "WHEEL_DOWN", "command": ["script-binding", "file_browser/dynamic/scroll_down"] }, { "key": "UP", "command": ["osd-auto", "add", "volume", "2"] }, { "key": "DOWN", "command": ["osd-auto", "add", "volume", "-2"] } ] ``` -------------------------------- ### fb.coroutine.callback(time_limit) with timeout Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Shows how to pass a time_limit to fb.coroutine.callback() to implement a timeout. If the callback does not run within the limit, the coroutine is resumed with false as the first argument, and the example aborts the async command and logs an error. ```lua local function execute(args) local t = mp.command_native_async({ name = "subprocess", playback_only = false, capture_stdout = true, capture_stderr = true, args = args }, fb.coroutine.callback(10)) local success, _, cmd = coroutine.yield() if not success then mp.abort_async_command(t) msg.error("command timed out") return nil end return cmd.status == 0 and cmd.stdout or nil end ``` -------------------------------- ### fb.parse_directory(directory: string, parse?: parse_state_table): (list_table, opts_table) | nil Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Starts a new scan for the given directory and returns a list_table and opts_table on success and nil on failure. Must be called from inside a coroutine. ```APIDOC ## [FUNCTION] fb.parse_directory(directory: string, parse?: parse_state_table): (list_table, opts_table) | nil ### Description Starts a new scan for the given directory and returns a list_table and opts_table on success and `nil` on failure. Must be called from inside a [coroutine](#coroutines). This function allows addons to request the contents of directories from the loaded parsers. There are no protections against infinite recursion, so be careful about calling this from within another parse. ### Parameters - **directory** (string) - Required - The directory to parse. - **parse** (parse_state_table) - Optional - A table with `source` and `properties` fields. If `parse.source` is not set, it will be set to `"addon"`. ### Returns - **(list_table, opts_table)** - On success, returns a list_table and opts_table. - **nil** - On failure. ### Notes - The parse does not use the actual table passed to this function; values are copied out. Only the `source` and `properties` fields can be used. - Every parse operation is expected to have its own unique coroutine. If multiple `parse_directory` operations are run within a single coroutine, file-browser will automatically create a new coroutine for the scan, which hands execution back to the original coroutine upon completion. - For creating virtual directories or modifying results of other parsers, use `defer` instead. ``` -------------------------------- ### Custom keybind with condition expression Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/custom-keybinds.md Shows how to define custom keybinds with conditions that evaluate Lua expressions. The first keybind triggers only when the current path starts with 'C:/', and the second triggers only when the selected file has a .mkv extension. Conditions can use item-specific codes like %F and %N. ```json [ { "key": "KP1", "command": ["print-text", "in my C:/ drive!"], "condition": "(%P):find('C:/') == 1" }, { "key": "KP2", "command": ["print-text", "Matroska File!"], "condition": "fb.get_extension(%N) == 'mkv'" } ] ``` -------------------------------- ### fb.coroutine.callback() basic usage Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Shows the basic pattern for using fb.coroutine.callback() with mp.command_native_async to run a subprocess without blocking the script. The callback resumes the current coroutine, and the example yields to wait for the result, returning stdout on success. ```lua local function execute(args) mp.command_native_async({ name = "subprocess", playback_only = false, capture_stdout = true, capture_stderr = true, args = args }, fb.coroutine.callback()) local _, cmd = coroutine.yield() return cmd.status == 0 and cmd.stdout or nil end ``` -------------------------------- ### Run Lua statement with `run-statement` - rename file Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/custom-keybinds.md Runs a Lua statement as a function body. This example uses mpv-user-input to rename the selected file, with error handling and a rescan after renaming. ```json { "key": "KP1", "command": ["script-message", "run-statement", "assert(user_input, 'install mpv-user-input!')", "local line, err = user_input.get_user_input_co({", "id = 'rename-file',", "source = 'custom-keybind',", "request_text = 'rename file:',", "queueable = true,", "default_input = %N,", "cursor_pos = #(%N) - #fb.get_extension(%N, '')", "})", "if not line then return end", "os.rename(%F, utils.join_path(%P, line))", "fb.rescan()" ], "parser": "file", "multiselect": true } ``` -------------------------------- ### Evaluate expressions with `evaluate-expressions` - basic arithmetic Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/custom-keybinds.md Evaluates embedded Lua expressions in the command. Expressions must be surrounded by `!{}`. This example prints the result of `1 + 2` (3) to the console. ```json { "key": "KP1", "command": ["script-message", "evaluate-expressions", "print-text", "!{1 + 2}"], } ``` -------------------------------- ### Conditional command with `conditional-command` - paused check Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/custom-keybinds.md Runs the following command only if the condition expression evaluates to true. This example checks if the player is paused using `mp.get_property_bool('pause')`. ```json { "key": "KP1", "command": ["script-message", "conditional-command", "mp.get_property_bool('pause')", "print-text", "is paused"], } ``` -------------------------------- ### fb.get_platform(): string Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Returns the platform string from mpv or a fallback for older versions. ```APIDOC ## [GET] fb.get_platform() ### Description Returns the contents of the `platform` property on mpv v0.36+, and `windows`, `darwin`, or `other` on older versions. ### Method GET ### Endpoint fb.get_platform() ### Parameters None ### Response #### Success Response (200) - **string** (string) - The platform identifier. #### Response Example "linux" ``` -------------------------------- ### Return list with sorted and filtered opts Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Returns a list with the opts table set to disable filtering and sorting, so file-browser does not re-order or filter the list. The opts table is optional and can be nil; only the listed keys are used. ```lua function parser:parse(directory, state) local list = { { name = "first/", type = "dir" }, { name = "second/", type = "dir" }, { name = "third/", type = "dir" }, { name = "file%01", type = "file", label = "file1" }, { name = "file2", type = "file", path = "https://youtube.com/video" }, } return list, { sorted = true, filtered = true } end ``` -------------------------------- ### Static list table returned by parse() Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Returns a static list of directory items with name and type fields. Demonstrates optional fields like label and path. Directories must end with '/' and paths must not contain backslashes. ```lua function parser:parse(directory, state) local list = { { name = "first/", type = "dir" }, { name = "second/", type = "dir" }, { name = "third/", type = "dir" }, { name = "file%01", type = "file", label = "file1" }, { name = "file2", type = "file", path = "https://youtube.com/video" }, } return list end ``` -------------------------------- ### Passthrough Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Describes how keybind functions can control passthrough behavior by returning false to run the next priority command. ```APIDOC ## Passthrough ### Description If the `passthrough` field of the keybind_table is set to `true` or `false` then file-browser will handle everything. However, if the passthrough field is not set (meaning the behaviour should be automatic) then it is up to the addon to ensure that they are correctly notifying when the operation failed and a passthrough should occur. In order to tell the keybind handler to run the next priority command, the keybind function simply needs to return the value `false`, any other value (including `nil`) will be treated as a successful operation. ### Return Value - **false** - Indicates that the operation failed and a passthrough should occur, causing the keybind handler to run the next priority command. - **any other value** (including nil) - Treated as a successful operation. ### Example The below example only allows removing files from the `/tmp/` directory and allows other keybinds to run in different directories: ```lua local fb = require "file-browser" -- see #api-functions and #utility-functions local function main(keybind, state, co) if state.directory ~= "/tmp/" then return false end for index, item in state.list do if state.selection[index] and item.type == "file" then os.remove( fb.get_full_path(item, state.directory) ) end end end parser.keybinds = { { "Alt+DEL", "delete_files", main, {} }, } ``` ``` -------------------------------- ### fb.get_opt(name: string): string | number | boolean Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Returns the script-opt with the given name. ```APIDOC ## [GET] fb.get_opt(name: string) ### Description Returns the script-opt with the given name. ### Method GET ### Endpoint fb.get_opt(name: string) ### Parameters #### Path Parameters - **name** (string) - Required - The name of the script-opt. ### Response #### Success Response (200) - **string | number | boolean** (mixed) - The value of the script-opt. #### Response Example "value" ``` -------------------------------- ### Implement delete_files keybind using state table Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Shows how to define a keybind function that uses the state table to delete selected files. The function iterates over the list, checks the selection and file type, and removes the file using fb.get_full_path. The keybind is registered with the parser.keybinds table. ```lua local fb = require "file-browser" -- see #api-functions and #utility-functions local function main(keybind, state, co) for index, item in state.list do if state.selection[index] and item.type == "file" then os.remove( fb.get_full_path(item, state.directory) ) end end end parser.keybinds = { { "Alt+DEL", "delete_files", main, {} }, } ``` -------------------------------- ### Chaining script messages with `=>` Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/custom-keybinds.md Use this keybind to chain multiple utility script messages together. The `=>` string is substituted for `script-message`, allowing sequential execution of commands. ```json { "key": "KP1", "command": ["script-message", "=>", "delay-command", "%j * 2", "=>", "evaluate-expressions", "print-text", "!{%j * 2}"], "multiselect": true } ``` -------------------------------- ### fb.get_current_parser_keyname(): string Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Returns the keybind_name of the parser that successfully parsed the current directory. ```APIDOC ## [GET] fb.get_current_parser_keyname() ### Description Returns the `keybind_name` of the parser that successfully parsed the current directory. Used for custom-keybind filtering. ### Method GET ### Endpoint fb.get_current_parser_keyname() ### Parameters None ### Response #### Success Response (200) - **string** (string) - The keybind name of the parser. #### Response Example "parser_keybind_name" ``` -------------------------------- ### fb.join_path(p1: string, p2: string): string Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Joins two path components, treating network protocol paths as absolute. Wraps mp.utils.join_path. ```APIDOC ## fb.join_path(p1: string, p2: string): string ### Description A wrapper around [`mp.utils.join_path`](https://mpv.io/manual/master/#lua-scripting-utils-join-path(p1,-p2)) which treats paths with network protocols as absolute paths. ### Parameters - **p1** (string) - Required - The first path component. - **p2** (string) - Required - The second path component. ### Returns - **string** - The joined path. ``` -------------------------------- ### Mixed keybind forms with native function and command table Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Shows that the command field of the custom-keybind syntax can be an array, and the 3rd value in the array syntax can be a table of mpv commands. Both forms are valid and can be mixed in the same keybinds table. The native function form uses a Lua function, while the command table form uses an array of mpv commands. ```lua local function main(keybind, state, co) -- deletes files end -- this is a valid keybind table parser.keybinds = { { "Alt+DEL", "delete_files", {"run", "rm", "%F"}, {} }, { key = "Alt+DEL", name = "delete_files", command = main } } ``` -------------------------------- ### fb.browse_directory(directory: string, open_browser: bool = true): coroutine Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Opens a directory in the browser, optionally opening the browser if closed. Returns a coroutine for the parse operation. ```APIDOC ## fb.browse_directory(directory: string, open_browser: bool = true): coroutine ### Description Opens the given directory in the browser. The cache is never used. If `open_browser` is truthy or `nil`, the browser will be opened if it is currently closed. If `open_browser` is `false`, the directory will be opened in the background. Returns the coroutine of the upcoming parse operation. ### Method N/A (function) ### Endpoint N/A ### Parameters - **directory** (string) - Required - The directory path to open. - **open_browser** (bool) - Optional - Whether to open the browser if closed. Defaults to `true`. ### Response - **coroutine** (coroutine) - The coroutine of the upcoming parse operation. ``` -------------------------------- ### fb.get_directory(): string Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Returns the current directory open in the browser. ```APIDOC ## [GET] fb.get_directory() ### Description Returns the current directory open in the browser. ### Method GET ### Endpoint fb.get_directory() ### Parameters None ### Response #### Success Response (200) - **string** (string) - The current directory path. #### Response Example "/home/me/" ``` -------------------------------- ### Keybind Function Call Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Describes the signature and usage of a keybind function, including the keybind table, state table, and coroutine parameters. ```APIDOC ## Keybind Function Call ### Description Keybind functions are called directly in the form `fn(keybind, state, coroutine)` where `keybind` is the keybind_table of the key being run, `state` is a table of state values at the time of the key press, and `coroutine` is the coroutine object that the keybind is being executed inside. ### Parameters - **keybind** (table) - Required - The keybind table using the same fields as defined in custom-keybinds.md. Any random extra fields placed in the original file-browser-keybinds.json will likely show up as well. - **state** (table) - Required - A table of state values at the time of the key press. See State Table section for details. - **coroutine** (coroutine) - Required - The coroutine object that the keybind is being executed inside. ### State Table The state table contains copies of the following values at the time of the key press: | key | description | |-----------------|-------------------------------------------------------------------------------------------------------------------------------------------| | directory | the current directory | | directory_label | the current directory_label - can (and often will) be `nil` | | list | the current list_table | | selected | index of the currently selected list item | | selection | table of currently selected items (for multi-select) - in the form { index = true, ... } - always available even if the `multiselect` flag is not set | | parser | a copy of the parser object that provided the current directory | ### Example ```lua local fb = require "file-browser" -- see #api-functions and #utility-functions local function main(keybind, state, co) for index, item in state.list do if state.selection[index] and item.type == "file" then os.remove( fb.get_full_path(item, state.directory) ) end end end parser.keybinds = { { "Alt+DEL", "delete_files", main, {} }, } ``` ``` -------------------------------- ### fb.get_parsers(): table Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Returns a table of all the loaded parsers/addons. ```APIDOC ## [GET] fb.get_parsers() ### Description Returns a table of all the loaded parsers/addons. The formatting of this table is undefined, but it should always contain an array of the parsers in order of priority. ### Method GET ### Endpoint fb.get_parsers() ### Parameters None ### Response #### Success Response (200) - **table** (table) - An array of parser objects. #### Response Example [] ``` -------------------------------- ### fb.get_audio_extensions(): table Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Returns a set of extensions for additional audio tracks, as a copy of the internal table. ```APIDOC ## [GET] fb.get_audio_extensions() ### Description Returns a set of extensions like `fb.get_extensions` but for extensions that are opened as additional audio tracks. All of these are included in `fb.get_extensions`. ### Method GET ### Endpoint fb.get_audio_extensions() ### Parameters None ### Response #### Success Response (200) - **table** (table) - A set of extensions (e.g., `{ mkv = true, mp3 = true }`). #### Response Example { "mkv": true, "mp3": true } ``` -------------------------------- ### fb.register_directory_mapping(directory: string | nil, mapping: string, pattern?: bool): void Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Creates or removes a directory mapping from an external path to an internal directory. Supports pattern matching. ```APIDOC ## fb.register_directory_mapping(directory: string | nil, mapping: string, pattern?: bool): void ### Description Creates a directory mapping for the given directory. A directory mapping is a one-way mapping from an external directory string to an internal directory within file-browser's directory tree. If `directory` is `nil`, the existing mapping for `mapping` is removed. If `pattern` is `true`, `mapping` is treated as a Lua pattern. ### Method N/A (function) ### Endpoint N/A ### Parameters - **directory** (string | nil) - Required - The internal directory path to map to, or `nil` to remove a mapping. - **mapping** (string) - Required - The external path string or pattern to map from. - **pattern** (bool) - Optional - If `true`, `mapping` is treated as a Lua pattern. ### Response No return value. ``` -------------------------------- ### parser:get_index(): number Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Returns the index of the parser in order of preference. ```APIDOC ## [GET] parser:get_index() ### Description Returns the index of the parser in order of preference (based on the priority value). `defer` uses this internally. ### Method GET ### Endpoint parser:get_index() ### Parameters None ### Response #### Success Response (200) - **number** (number) - The parser index. #### Response Example 0 ``` -------------------------------- ### fb.get_extensions(): table Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Returns the set of valid extensions after applying the user's whitelist/blacklist options. ```APIDOC ## [GET] fb.get_extensions() ### Description Returns the set of valid extensions after applying the user's whitelist/blacklist options. The table is in the form `{ mkv = true, mp3 = true, ... }`. Sub extensions, audio extensions, and parseable extensions are all included in this set. ### Method GET ### Endpoint fb.get_extensions() ### Parameters None ### Response #### Success Response (200) - **table** (table) - A set of extensions. #### Response Example { "mkv": true, "mp3": true } ``` -------------------------------- ### Hide OSC logo with conditional auto-profile (older mpv) Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/README.md For mpv versions before v0.36, use the `file_browser-open` field of the `shared-script-properties` property instead. The condition checks if the field equals "yes". ```properties [hide-logo] profile-cond= idle_active and shared_script_properties["file_browser-open"] == "yes" profile-restore=copy osc=no ``` -------------------------------- ### parser:register_root_item(item: string | item_table, priority?: number): boolean Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md A wrapper around fb.register_root_item which uses the parser's priority value if priority is undefined. ```APIDOC ## [FUNCTION] parser:register_root_item(item: string | item_table, priority?: number): boolean ### Description A wrapper around [`fb.register_root_item`](#fbregister_root_itemitem-string--item_table-priority-number-boolean) which uses the parser's priority value if `priority` is undefined. ### Parameters - **item** (string | item_table) - Required - The item to register. If a string, a new item_table is created with `{ type = 'dir', name = item }`. If an item_table, it must be a valid directory item. - **priority** (number) - Optional - Priority value. If undefined, uses the parser's priority value. ### Returns - **boolean** - Whether the item was added. ``` -------------------------------- ### fb.evaluate_string(str: string, chunkname?: string, env?: table, defaults?: bool = true): unknown Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Loads str as a chunk of Lua statement(s) and runs them, returning the result. Errors are propagated to the caller. ```APIDOC ## fb.evaluate_string(str: string, chunkname?: string, env?: table, defaults?: bool = true): unknown ### Description Loads str as a chunk of Lua statement(s) and runs them, returning the result. Errors are propagated to the caller. ### Parameters #### Path Parameters - **str** (string) - Required - The Lua code to evaluate. - **chunkname** (string) - Optional - Used for debug output and error messages. - **env** (table) - Optional - A custom environment table. Inheritance from the global table is disabled if defaults is false. - **defaults** (bool) - Optional - If false, disables inheritance from the global table. Defaults to true. ### Returns - **unknown** - The result of the evaluated code. ### Example ```lua fb.evaluate_string('return 5 + 5') -- 10 fb.evaluate_string('x = 20 ; return x * x') -- 400 ``` ``` -------------------------------- ### fb.get_script_opts(): table Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Returns the table of script opts set by the user. ```APIDOC ## [GET] fb.get_script_opts() ### Description Returns the table of script opts set by the user. This currently does not get changed during runtime, but that is not guaranteed for future minor version increments. ### Method GET ### Endpoint fb.get_script_opts() ### Parameters None ### Response #### Success Response (200) - **table** (table) - The script opts table. #### Response Example {} ``` -------------------------------- ### parser:defer(directory: string): (list_table, opts_table) | nil Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Forwards the given directory to the next valid parser. For use from within a parse operation. It allows scripts to create virtual directories or modify results of other parsers. ```APIDOC ## parser:defer(directory: string): (list_table, opts_table) | nil ### Description Forwards the given directory to the next valid parser. For use from within a parse operation. It allows scripts to create virtual directories or modify results of other parsers. ### Parameters #### Path Parameters - **directory** (string) - Required - The directory to forward to the next parser. ### Returns - **list_table** (list_table) - The list of files and directories from the next parser. - **opts_table** (opts_table) - The options table from the next parser. - **nil** - If no next parser is available. ### Example ```lua function home_label:parse(directory, ...) local list, opts = self:defer(directory, ...) -- modify opts and list as needed return list, opts end ``` ``` -------------------------------- ### fb.get_protocol(url: string, def?: any): string | def Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Extracts the protocol scheme from a URL string. Returns nil if no scheme is found, or a default value if provided. ```APIDOC ## fb.get_protocol(url: string, def?: any): string | def ### Description Returns the protocol scheme for the string `url`, or `nil` if there is no scheme. If `def` is defined then that is returned instead of `nil`. The `://` is not included, so `https://example.com/test.mkv` will return `https`. ### Parameters - **url** (string) - Required - The URL to extract the protocol from. - **def** (any) - Optional - Default value to return if no scheme exists. ### Returns - **string** - The protocol scheme without the `://`. - **def** - The provided default value if no scheme exists. ``` -------------------------------- ### fb.fix_path(path: string, is_directory?: boolean): string Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Formats a given path into a file-browser compatible path string. Optionally formats the path as a directory when the second argument is true. ```APIDOC ## fb.fix_path(path: string, is_directory?: boolean): string ### Description Takes a path and returns a file-browser compatible path string. The optional second argument is a boolean that tells the function to format the path to be a directory. ### Parameters - **path** (string) - Required - The path to format. - **is_directory** (boolean) - Optional - If true, formats the path as a directory. ### Returns - **string** - The formatted path string. ``` -------------------------------- ### Custom-keybind table form Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Defines a keybind using the custom-keybind table syntax, with key, name, command, and filter fields. The command is a table of mpv commands. This form allows additional options like filter, which are not available in the array form. ```lua parser.keybinds = { { key = "Alt+DEL", name = "delete_files", command = {"run", "rm", "%F"}, filter = "files" } } ``` -------------------------------- ### Conditional command with `conditional-command` - extension check Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/custom-keybinds.md Runs the command only if the currently selected item in the browser has a `.mkv` extension. Uses `fb.get_extension(%N)` to check the extension. ```json { "key": "KP1", "command": ["script-message", "conditional-command", "fb.get_extension(%N) == 'mkv'", "print-text", "a matroska file"], } ``` -------------------------------- ### fb.get_root(): list_table Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Returns the root table. ```APIDOC ## [GET] fb.get_root() ### Description Returns the root table. ### Method GET ### Endpoint fb.get_root() ### Parameters None ### Response #### Success Response (200) - **list_table** (table) - The root table. #### Response Example {} ``` -------------------------------- ### fb.coroutine.resume_catch(co: coroutine, ...): (boolean, ...) Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Resumes a coroutine, catching and logging any errors. Returns all values from coroutine.resume. ```APIDOC ## [FUNCTION] fb.coroutine.resume_catch(co: coroutine, ...): (boolean, ...) ### Description Runs coroutine.resume(co, ...) with the given coroutine, passing through any additional arguments. If the coroutine throws an error, an error message and stacktrace are printed to the console. All return values of coroutine.resume are caught and returned. ### Parameters - **co** (coroutine) - Required - The coroutine to resume. - **...** (any) - Optional - Additional arguments to pass to the coroutine. ### Returns - **(boolean, ...)** - The success boolean and any return values from the coroutine. ``` -------------------------------- ### fb.get_current_parser(): string Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Returns the unique id of the parser that successfully parsed the current directory. ```APIDOC ## [GET] fb.get_current_parser() ### Description Returns the unique id of the parser that successfully parsed the current directory. ### Method GET ### Endpoint fb.get_current_parser() ### Parameters None ### Response #### Success Response (200) - **string** (string) - The unique parser id. #### Response Example "parser_id" ``` -------------------------------- ### fb.rescan(): coroutine Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Rescans the current directory, equivalent to Ctrl+r. Returns the coroutine of the upcoming parse operation. ```APIDOC ## [FUNCTION] fb.rescan(): coroutine ### Description Rescans the current directory. Equivalent to Ctrl+r. Returns the coroutine of the upcoming parse operation. The parse is queued and run when the script thread next goes idle, allowing one to store this value and use it to identify the triggered parse operation. ### Returns - **coroutine** - The coroutine of the upcoming parse operation. ``` -------------------------------- ### fb.get_dvd_device(): string Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Returns the current dvd-device as reported by mpv's dvd-device property. Deprecated. ```APIDOC ## [GET] fb.get_dvd_device() ### Description *DEPRECATED*. Returns the current dvd-device as reported by mpv's `dvd-device` property. Formatted to work with file-browser. ### Method GET ### Endpoint fb.get_dvd_device() ### Parameters None ### Response #### Success Response (200) - **string** (string) - The dvd device path. #### Response Example "/dev/sr0" ``` -------------------------------- ### fb.register_parseable_extension(ext: string): void Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Registers a file extension that the browser will attempt to open like a directory, for addons that can parse files. ```APIDOC ## fb.register_parseable_extension(ext: string): void ### Description Registers a file extension that the browser will attempt to open like a directory. This is useful for addons that can parse files such as playlist files. ### Method N/A (function) ### Endpoint N/A ### Parameters - **ext** (string) - Required - The file extension to register. ### Response No return value. ``` -------------------------------- ### fb.iterate_opt(opts: string): iterator Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Creates an iterator function over a list of items separated by root separators defined in the configuration. Useful for parsing option strings. ```APIDOC ## fb.iterate_opt(opts: string): iterator ### Description Takes an options string consisting of a list of items separated by the `root_separators` defined in `file_browser.conf` and returns an iterator function that can be used to iterate over each item in the list. ### Parameters - **opts** (string) - Required - The options string to iterate over. ### Returns - **iterator** - A function that returns the next item each time it is called. ### Example ```lua local opt = "a,b,zz z" -- root_separators=, for item in fb.iterate_opt(opt) do print(item) -- prints: 'a', 'b', 'zz z' end ``` ``` -------------------------------- ### fb.get_current_file(): table Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Returns a table containing the path of the current open file. ```APIDOC ## [GET] fb.get_current_file() ### Description Returns a table containing the path of the current open file in the form: `{directory = "/home/me/", name = "bunny.mkv", path = "/home/me/bunny.mkv"}`. ### Method GET ### Endpoint fb.get_current_file() ### Parameters None ### Response #### Success Response (200) - **directory** (string) - The directory portion of the file path. - **name** (string) - The file name. - **path** (string) - The full path. #### Response Example { "directory": "/home/me/", "name": "bunny.mkv", "path": "/home/me/bunny.mkv" } ``` -------------------------------- ### fb.get_extension(filename: string, def?: any): string | def Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Returns the file extension for the given filename, or nil if no extension exists. If a default value is provided, it is returned instead of nil. ```APIDOC ## fb.get_extension(filename: string, def?: any): string | def ### Description Returns the file extension for the string `filename`, or `nil` if there is no extension. If `def` is defined then that is returned instead of `nil`. The full stop is not included in the extension, so `test.mkv` will return `mkv`. ### Parameters - **filename** (string) - Required - The filename to extract the extension from. - **def** (any) - Optional - Default value to return if no extension exists. ### Returns - **string** - The file extension without the dot. - **def** - The provided default value if no extension exists. ``` -------------------------------- ### fb.redraw(): void Source: https://github.com/cogentredtester/mpv-file-browser/blob/master/docs/addons.md Forces a redraw of the browser UI. ```APIDOC ## [FUNCTION] fb.redraw(): void ### Description Forces a redraw of the browser UI. ### Returns - **void** - This function does not return a value. ```