From 38ad1ed03b2a3ff8ae8ebed56d2d24239e5ca15e Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Thu, 30 Jan 2025 14:32:49 -0600 Subject: [PATCH] command: normalize paths for path and track-list/N/external-filename It's better for API users to actually get predictable results. --- DOCS/interface-changes/property-paths.txt | 1 + DOCS/man/input.rst | 5 +---- player/command.c | 13 ++++++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 DOCS/interface-changes/property-paths.txt diff --git a/DOCS/interface-changes/property-paths.txt b/DOCS/interface-changes/property-paths.txt new file mode 100644 index 0000000000..7a116322c7 --- /dev/null +++ b/DOCS/interface-changes/property-paths.txt @@ -0,0 +1 @@ +the `path` and `track-list/N/external-filename` properties now always return a full, absolute path diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 98c1a73098..570357da59 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -2109,10 +2109,7 @@ Property list Process-id of mpv. ``path`` - Full path of the currently played file. Usually this is exactly the same - string you pass on the mpv command line or the ``loadfile`` command, even - if it's a relative path. If you expect an absolute path, you will have to - determine it yourself, for example by using the ``normalize-path`` command. + Full absolute path of the currently played file. ``stream-open-filename`` The full path to the currently played media. This is different from diff --git a/player/command.c b/player/command.c index eb0339a31d..8c64262889 100644 --- a/player/command.c +++ b/player/command.c @@ -507,7 +507,10 @@ static int mp_property_path(void *ctx, struct m_property *prop, MPContext *mpctx = ctx; if (!mpctx->filename) return M_PROPERTY_UNAVAILABLE; - return m_property_strdup_ro(action, arg, mpctx->filename); + char *path = mp_normalize_path(NULL, mpctx->filename); + int r = m_property_strdup_ro(action, arg, path); + talloc_free(path); + return r; } static int mp_property_filename(void *ctx, struct m_property *prop, @@ -1997,6 +2000,9 @@ static int get_track_entry(int item, int action, void *arg, void *ctx) struct MPContext *mpctx = ctx; struct track *track = mpctx->tracks[item]; + char *external_filename = mp_normalize_user_path(NULL, mpctx->global, + track->external_filename); + struct mp_codec_params p = track->stream ? *track->stream->codec : (struct mp_codec_params){0}; @@ -2048,8 +2054,8 @@ static int get_track_entry(int item, int action, void *arg, void *ctx) {"external", SUB_PROP_BOOL(track->is_external)}, {"selected", SUB_PROP_BOOL(track->selected)}, {"main-selection", SUB_PROP_INT(order), .unavailable = order < 0}, - {"external-filename", SUB_PROP_STR(track->external_filename), - .unavailable = !track->external_filename}, + {"external-filename", SUB_PROP_STR(external_filename), + .unavailable = !external_filename}, {"ff-index", SUB_PROP_INT(track->ff_index)}, {"hls-bitrate", SUB_PROP_INT(track->hls_bitrate), .unavailable = !track->hls_bitrate}, @@ -2123,6 +2129,7 @@ static int get_track_entry(int item, int action, void *arg, void *ctx) } done: + talloc_free(external_filename); talloc_free(tag_list); return ret; }