diff options
author | wm4 <wm4@nowhere> | 2016-08-11 22:40:00 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-08-11 22:40:00 +0200 |
commit | dc6f8d4a0af27f32ff9d8df86cae6ad2df4aefcc (patch) | |
tree | c9a6093b279351d44a5983895e6d72567743c381 | |
parent | 9024cb168586dcc7808893e944edb217b34aa56f (diff) | |
download | mpv-dc6f8d4a0af27f32ff9d8df86cae6ad2df4aefcc.tar.bz2 mpv-dc6f8d4a0af27f32ff9d8df86cae6ad2df4aefcc.tar.xz |
command: add a property that returns filename without extension
Requested. Fixes #3404.
-rw-r--r-- | DOCS/man/input.rst | 6 | ||||
-rw-r--r-- | player/command.c | 14 |
2 files changed, 19 insertions, 1 deletions
diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 46dcb36e7d..10fd6e2b1c 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -869,6 +869,12 @@ Property list looks better for display purposes. Use the ``path`` property to get an unmodified filename.) + This has a sub-property: + + ``filename/no-ext`` + Like the ``filename`` property, but if the text contains a ``.``, strip + all text after the last ``.``. Usually this removes the file extension. + ``file-size`` Length in bytes of the source file/stream. (This is the same as ``${stream-end}``. For ordered chapters and such, the diff --git a/player/command.c b/player/command.c index d8f4f83529..584cc11cdc 100644 --- a/player/command.c +++ b/player/command.c @@ -346,7 +346,19 @@ static int mp_property_filename(void *ctx, struct m_property *prop, if (mp_is_url(bstr0(filename))) mp_url_unescape_inplace(filename); char *f = (char *)mp_basename(filename); - int r = m_property_strdup_ro(action, arg, f[0] ? f : filename); + if (!f[0]) + f = filename; + if (action == M_PROPERTY_KEY_ACTION) { + struct m_property_action_arg *ka = arg; + if (strcmp(ka->key, "no-ext") == 0) { + action = ka->action; + arg = ka->arg; + bstr root; + if (mp_splitext(f, &root)) + f = bstrto0(filename, root); + } + } + int r = m_property_strdup_ro(action, arg, f); talloc_free(filename); return r; } |