Home

Awesome

mpv-file-browser

cover

This script allows users to browse and open files and folders entirely from within mpv. The script uses nothing outside the mpv API, so should work identically on all platforms. The browser can move up and down directories, start playing files and folders, or add them to the queue.

By default only file types compatible with mpv will be shown, but this can be changed in the config file.

This script requires at least mpv v0.33.

Originally, file-browser worked with versions of mpv going back to v0.31, you can find those (now unsupported) older versions of file-browser here

Installation

Basic

Clone this git repository into the mpv ~~/scripts directory and change the name of the folder from mpv-file-browser to file-browser. You can then pull to receive updates. Alternatively, you can download the zip and extract the contents to ~~/scripts/file-browser. ~~/ is the mpv config directory which is typically ~/.config/mpv/ on linux and %APPDATA%/mpv/ on windows.

Create a file_browser.conf file in the ~~/script-opts/ directory and customise the root option for your system. The docs/file_browser.conf file contains the full list of options and their defaults.

Advanced

To setup custom keybinds enable the custom_keybinds option in file_browser.conf and create a ~~/script-opts/file-browser-keybinds.json file. Do not copy the file-browser-keybinds.json file stored in this repository, that file is a collection of random examples, many of which are for completely different operating systems. Use them and the docs to create your own collection of keybinds.

To setup addons enable the addons option in file_browser.conf and place the addon files in the ~~/script-modules/file-browser-addons/ directory.

If you are not going to enable custom keybinds or addons then there is no reason to create file-browser-keybinds.json or script-modules/file-browser-addons/.

Keybinds

The following keybinds are set by default

KeyNameDescription
MENUbrowse-filestoggles the browser
Ctrl+oopen-browseropens the browser
Alt+obrowse-directory/get-user-inputopens a dialogue box to type in a directory - requires mpv-user-input

The following dynamic keybinds are only set while the browser is open:

KeyNameDescription
ESCclosecloses the browser or clears the selection
ENTERplayplays the currently selected file or folder
Shift+ENTERplay_appendappends the current file or folder to the playlist
Alt+ENTERplay_autoloadloads playlist entries before and after the selected file (like autoload.lua)
RIGHTdown_direnter the currently selected directory
LEFTup_dirmove to the parent directory
DOWNscroll_downmove selector down the list
UPscroll_upmove selector up the list
PGDWNpage_downmove selector down the list by a page (the num_entries option)
PGUPpage_upmove selector up the list by a page (the num_entries option)
Shift+PGDWNlist_bottommove selector to the bottom of the list
Shift+PGUPlist_topmove selector to the top of the list
HOMEgoto_currentmove to the directory of the currently playing file
Shift+HOMEgoto_rootmove to the root directory
Ctrl+rreloadreload directory and reset cache
sselect_modetoggles multiselect mode
Sselect_itemtoggles selection for the current item
Ctrl+aselect_allselect all items in the current directory

When attempting to play or append a subtitle file the script will instead load the subtitle track into the existing video.

The behaviour of the autoload keybind can be reversed with the autoload script-opt. By default the playlist will only be autoloaded if Alt+ENTER is used on a single file, however when the option is switched autoload will always be used on single files unless Alt+ENTER is used. Using autoload on a directory, or while appending an item, will not work.

Root Directory

To accomodate for both windows and linux this script has its own virtual root directory where drives and file folders can be manually added. The root directory can only contain folders.

The root directory is set using the root option, which is a comma separated list of directories. Entries are sent through mpv's expand-path command. By default the only root value is the user's home folder:

root=~/

It is highly recommended that this be customised for the computer being used; file_browser.conf contains commented out suggestions for generic linux and windows systems. For example, my windows root looks like:

root=~/,C:/,D:/,E:/,Z:/

Multi-Select

By default file-browser only opens/appends the single item that the cursor has selected. However, using the s keybinds specified above, it is possible to select multiple items to open all at once. Selected items are shown in a different colour to the cursor. When in multiselect mode the cursor changes colour and scrolling up and down the list will drag the current selection. If the original item was unselected, then dragging will select items, if the original item was selected, then dragging will unselect items.

When multiple items are selected using the open or append commands all selected files will be added to the playlist in the order they appear on the screen. The currently selected (with the cursor) file will be ignored, instead the first multi-selected item in the folder will follow replace/append behaviour as normal, and following selected items will be appended to the playlist afterwards in the order that they appear on the screen.

Custom Keybinds

File-browser also supports custom keybinds. These keybinds send normal input commands, but the script will substitute characters in the command strings for specific values depending on the currently open directory, and currently selected item. This allows for a wide range of customised behaviour, such as loading additional audio tracks from the browser, or copying the path of the selected item to the clipboard.

To see how to enable and use custom keybinds, see custom-keybinds.md.

Add-ons

Add-ons are ways to add extra features to file-browser, for example adding support for network file servers like ftp, or implementing virtual directories in the root like recently opened files. They can be enabled by setting addon script-opt to yes, and placing the addon file into the ~~/script-modules/file-browser-addons/ directory.

For a list of existing addons see the wiki. For instructions on writing your own addons see addons.md.

Script Messages

File-browser supports a small number of script messages that allow the user or other scripts to talk with the browser.

browse-directory

script-message browse-directory [directory]

Opens the given directory in the browser. If the browser is currently closed it will be opened.

get-directory-contents

script-message get-directory-contents [directory] [response-string]

Reads the given directory, and sends the resulting tables to the specified script-message in the format:

script-message [response-string] [list] [opts]

The list and opts tables are formatted as json strings through the mp.utils.format_json function. See addons.md for how the tables are structured, and what each field means. The API_VERSION field of the opts table refers to what version of the addon API file browser is using. The response-string refers to an arbitrary script-message that the tables should be sent to.

This script-message allows other scripts to utilise file-browser's directory parsing capabilities, as well as those of the file-browser addons.

Configuration

See file_browser.conf for the full list of options and their default values. The file is placed in the ~~/script-opts/ folder.

Conditional Auto-Profiles

file-browser provides a property that can be used with conditional auto-profiles to detect when the browser is open. On mpv v0.36+ you should use the user-data property with the file_browser/open boolean.

Here is an example of an auto-profile that hides the OSC logo when using file-browser in an idle window:

[hide-logo]
profile-cond= idle_active and user_data.file_browser.open
profile-restore=copy
osc=no

On older versions of mpv you can use the file_browser-open field of the shared-script-properties property:

[hide-logo]
profile-cond= idle_active and shared_script_properties["file_browser-open"] == "yes"
profile-restore=copy
osc=no

See #55 for more details on this.

mpv-user-input

mpv-user-input is a script that provides an API to request text input from the user over the OSD. It was built using console.lua as a base, so supports almost all the same text input commands. If user-input.lua is loaded by mpv, and user-input-module is in the ~~/script-modules/ directory, then using Alt+o will open an input box that can be used to directly enter directories for file-browser to open.