Skip to content

Commit b04e522

Browse files
committed
command: add back track-list/N/external-filename property
In addition to the no-ext variant. These actually return filenames now.
1 parent f5ae9f8 commit b04e522

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
`track-list/N/external-filename` was renamed to `track-list/N/external-path`
22
the `path` and `track-list/N/external-filename` properties always return a full, absolute path
3+
add `track-list/N/external-filename` and `track-list/N/external-filename/no-ext` properties

DOCS/man/input.rst

+8
Original file line numberDiff line numberDiff line change
@@ -3289,6 +3289,14 @@ Property list
32893289
``yes``/true if the track is an external file, ``no``/false or
32903290
unavailable otherwise. This is set for separate subtitle files.
32913291

3292+
``track-list/N/external-filename``
3293+
The filename if the track is from an external file, unavailable
3294+
otherwise.
3295+
3296+
``track-list/N/external-filename/no-ext``
3297+
Like ``track-list/N/external-filename`` but if the text contains a
3298+
``.``, strip all text after the last ``.``.
3299+
32923300
``track-list/N/external-path``
32933301
The absolute path if the track is from an external file, unavailable
32943302
otherwise.

player/command.c

+27
Original file line numberDiff line numberDiff line change
@@ -2002,6 +2002,27 @@ static int get_track_entry(int item, int action, void *arg, void *ctx)
20022002

20032003
char *external_path = mp_normalize_user_path(mpctx, mpctx->global,
20042004
track->external_filename);
2005+
char *external_filename = NULL;
2006+
char *external_filename_no_ext = NULL;
2007+
2008+
char *path_dup = talloc_strdup(NULL, external_path);
2009+
if (path_dup) {
2010+
if (mp_is_url(bstr0(path_dup)))
2011+
mp_url_unescape_inplace(path_dup);
2012+
char *basename = (char *)mp_basename(path_dup);
2013+
external_filename = talloc_strdup(NULL, basename);
2014+
talloc_free(path_dup);
2015+
}
2016+
2017+
char *filename_dup = talloc_strdup(NULL, external_filename);
2018+
if (filename_dup) {
2019+
bstr root;
2020+
if (mp_splitext(filename_dup, &root)) {
2021+
char *no_ext = bstrto0(filename_dup, root);
2022+
external_filename_no_ext = talloc_strdup(NULL, no_ext);
2023+
}
2024+
talloc_free(filename_dup);
2025+
}
20052026

20062027
struct mp_codec_params p =
20072028
track->stream ? *track->stream->codec : (struct mp_codec_params){0};
@@ -2054,6 +2075,10 @@ static int get_track_entry(int item, int action, void *arg, void *ctx)
20542075
{"external", SUB_PROP_BOOL(track->is_external)},
20552076
{"selected", SUB_PROP_BOOL(track->selected)},
20562077
{"main-selection", SUB_PROP_INT(order), .unavailable = order < 0},
2078+
{"external-filename", SUB_PROP_STR(external_filename),
2079+
.unavailable = !external_filename},
2080+
{"external-filename/no-ext", SUB_PROP_STR(external_filename_no_ext),
2081+
.unavailable = !external_filename_no_ext},
20572082
{"external-path", SUB_PROP_STR(external_path),
20582083
.unavailable = !external_path},
20592084
{"ff-index", SUB_PROP_INT(track->ff_index)},
@@ -2129,6 +2154,8 @@ static int get_track_entry(int item, int action, void *arg, void *ctx)
21292154
}
21302155

21312156
done:
2157+
talloc_free(external_filename);
2158+
talloc_free(external_filename_no_ext);
21322159
talloc_free(external_path);
21332160
talloc_free(tag_list);
21342161
return ret;

0 commit comments

Comments
 (0)