Skip to content

Commit

Permalink
command: add filename/ext property
Browse files Browse the repository at this point in the history
This will return only the text after the last '.', if any present.
Otherwise, return an empty string.
  • Loading branch information
llyyr committed Oct 20, 2023
1 parent bd1ba99 commit 03d1dc7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion DOCS/man/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1861,12 +1861,16 @@ Property list
looks better for display purposes. Use the ``path`` property to get an
unmodified filename.)

This has a sub-property:
This has two sub-properties:

``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.

``filename/ext``
Returns the text after the final ``.``, if the text contains any.
Otherwise, returns an empty string.

``file-size``
Length in bytes of the source file/stream. (This is the same as
``${stream-end}``. For segmented/multi-part files, this will return the
Expand Down
10 changes: 9 additions & 1 deletion player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,21 @@ static int mp_property_filename(void *ctx, struct m_property *prop,
f = filename;
if (action == M_PROPERTY_KEY_ACTION) {
struct m_property_action_arg *ka = arg;
if (strcmp(ka->key, "no-ext") == 0) {
bstr key = bstr0(ka->key);
if (bstr_equals0(key, "no-ext")) {
action = ka->action;
arg = ka->arg;
bstr root;
if (mp_splitext(f, &root))
f = bstrto0(filename, root);
} else if (bstr_equals0(key, "ext")) {
action = ka->action;
arg = ka->arg;
f = mp_splitext(f, NULL);
if (!f)
f = talloc_strdup(NULL, "");;
}

}
int r = m_property_strdup_ro(action, arg, f);
talloc_free(filename);
Expand Down

0 comments on commit 03d1dc7

Please sign in to comment.