Skip to content

Commit

Permalink
DOCS/man/mpv: improve path docs and clarify config-dir path behavior
Browse files Browse the repository at this point in the history
The previous documentation was pretty scary and misleading, and was
also outdated in several sections.

It was also difficult to understand some of the paragraphs.

The path documentation has now been overhauled to be much easier
to understand and to document the latest mpv behavior.
  • Loading branch information
Arcitec committed Oct 31, 2024
1 parent 0c5420b commit d64d1fe
Showing 1 changed file with 36 additions and 15 deletions.
51 changes: 36 additions & 15 deletions DOCS/man/mpv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -499,32 +499,53 @@ console controls. (Which makes it suitable for playing data piped to stdin.)
The special argument ``--`` can be used to stop mpv from interpreting the
following arguments as options.

When using the client API, you should strictly avoid using ``mpv_command_string``
For paths passed to mpv CLI suboptions (options that have multiple `:` and
`,`-separated values), the situation is further complicated by the need to
escape special characters. To work around this, the path can instead be wrapped
in the "fixed-length" syntax, e.g. ``%n%string_of_length_n`` (see above).

When using the libmpv API, you should strictly avoid using ``mpv_command_string``
for invoking the ``loadfile`` command, and instead prefer e.g. ``mpv_command``
to avoid the need for filename escaping.

For paths passed to suboptions, the situation is further complicated by the
need to escape special characters. To work this around, the path can be
additionally wrapped in the fixed-length syntax, e.g. ``%n%string_of_length_n``
(see above).
The same applies when you're using the scripting API, where you should avoid using
``mp.command``, and instead prefer using the "separate parameters" variants (such
as ``mp.commandv`` or ``mp.command_native``), so that the filenames will always be
correctly interpreted.

Some mpv options will interpret special meanings for paths starting with ``~``,
making it easy to dynamically find special directories, such as referring to the
current user's home directory or the mpv configuration directory.

When using the special ``~`` prefix, there must always be a trailing ``/`` after
the special path prefix. In other words, ``~`` doesn't work, but ``~/`` will work.

The following special paths/keywords are currently recognized:

.. warning::

Beware that if ``--no-config`` is used, all of the "config directory"-based
paths (``~~/``, ``~~home/`` and ``~~global/``) will be empty strings.

This means that ``~~home/`` would expand to an empty string, and that
sub-paths such as ``~~home/foo/bar"`` would expand to "relative paths"
without any path prefix (``foo/bar``), which may not be what you expected.

Furthermore, any commands that search in config directories will fail
to find anything, since there won't be any directories to search in.

Some mpv options interpret paths starting with ``~``.
Currently, the prefix ``~~home/`` expands to the mpv configuration directory
(usually ``~/.config/mpv/``).
``~/`` expands to the user's home directory. (The trailing ``/`` is always
required.) The following paths are currently recognized:
Be sure that your scripts can handle these "no config" scenarios.

================ ===============================================================
Name Meaning
================ ===============================================================
``~~/`` If the subpath exists in any of the mpv's config directories
``~~/`` If the subpath exists in any of mpv's config directories, then
the path of the existing file/dir is returned. Otherwise this
is equivalent to ``~~home/``.
Note that if --no-config is used ``~~/foobar`` will resolve to
``foobar`` which can be unexpected.
``~/`` user home directory root (similar to shell, ``$HOME``)
``~/`` user home directory root (equivalent to ``$HOME`` in a shell)
``~~home/`` mpv config dir (for example ``~/.config/mpv/``)
``~~global/`` the global config path, if available (not on win32)
``~~global/`` the global config path (such as ``/etc/mpv``), if available
(not on win32)
``~~osxbundle/`` the macOS bundle resource path (macOS only)
``~~desktop/`` the path to the desktop (win32, macOS)
``~~exe_dir/`` win32 only: the path to the directory containing the exe (for
Expand Down

0 comments on commit d64d1fe

Please sign in to comment.