mirror of https://github.com/mpv-player/mpv
command: add a property that returns filename without extension
Requested. Fixes #3404.
This commit is contained in:
parent
9024cb1685
commit
dc6f8d4a0a
|
@ -869,6 +869,12 @@ Property list
|
||||||
looks better for display purposes. Use the ``path`` property to get an
|
looks better for display purposes. Use the ``path`` property to get an
|
||||||
unmodified filename.)
|
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``
|
``file-size``
|
||||||
Length in bytes of the source file/stream. (This is the same as
|
Length in bytes of the source file/stream. (This is the same as
|
||||||
``${stream-end}``. For ordered chapters and such, the
|
``${stream-end}``. For ordered chapters and such, the
|
||||||
|
|
|
@ -346,7 +346,19 @@ static int mp_property_filename(void *ctx, struct m_property *prop,
|
||||||
if (mp_is_url(bstr0(filename)))
|
if (mp_is_url(bstr0(filename)))
|
||||||
mp_url_unescape_inplace(filename);
|
mp_url_unescape_inplace(filename);
|
||||||
char *f = (char *)mp_basename(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);
|
talloc_free(filename);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue