History

command: normalize paths for path and track-list/N/external-filename

It's better for API users to actually get predictable results.

Dudemanguy committed 1 year ago

Commit 38ad1ed1 parent 02c0b343 files · +12 −7Browse files

Unified · Split

3 files
  1. DOCS/interface-changes/property-paths.txt +1 −0
  2. DOCS/man/input.rst +1 −4
  3. player/command.c +10 −3
DOCS/interface-changes/property-paths.txt+1−0
@@ -0,0 +1 @@
1+the `path` and `track-list/N/external-filename` properties now always return a full, absolute path
DOCS/man/input.rst+1−4
@@ -2109,10 +2109,7 @@ Property list · 2108 unmodified lines
21092109 Process-id of mpv.
21102110
21112111 ``path``
2112− Full path of the currently played file. Usually this is exactly the same
2113− string you pass on the mpv command line or the ``loadfile`` command, even
2114− if it's a relative path. If you expect an absolute path, you will have to
2115− determine it yourself, for example by using the ``normalize-path`` command.
2112+ Full absolute path of the currently played file.
21162113
21172114 ``stream-open-filename``
21182115 The full path to the currently played media. This is different from
player/command.c+10−3
@@ -507,7 +507,10 @@ static int mp_property_path(void *ctx, struct m_property *prop, · 506 unmodified lines
507507 MPContext *mpctx = ctx;
508508 if (!mpctx->filename)
509509 return M_PROPERTY_UNAVAILABLE;
510− return m_property_strdup_ro(action, arg, mpctx->filename);
510+ char *path = mp_normalize_path(NULL, mpctx->filename);
511+ int r = m_property_strdup_ro(action, arg, path);
512+ talloc_free(path);
513+ return r;
511514 }
512515
513516 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) · 1483 unmodified lines
19972000 struct MPContext *mpctx = ctx;
19982001 struct track *track = mpctx->tracks[item];
19992002
2003+ char *external_filename = mp_normalize_user_path(NULL, mpctx->global,
2004+ track->external_filename);
2005+
20002006 struct mp_codec_params p =
20012007 track->stream ? *track->stream->codec : (struct mp_codec_params){0};
20022008
@@ -2048,8 +2054,8 @@ static int get_track_entry(int item, int action, void *arg, void *ctx) · 45 unmodified lines
20482054 {"external", SUB_PROP_BOOL(track->is_external)},
20492055 {"selected", SUB_PROP_BOOL(track->selected)},
20502056 {"main-selection", SUB_PROP_INT(order), .unavailable = order < 0},
2051− {"external-filename", SUB_PROP_STR(track->external_filename),
2052− .unavailable = !track->external_filename},
2057+ {"external-filename", SUB_PROP_STR(external_filename),
2058+ .unavailable = !external_filename},
20532059 {"ff-index", SUB_PROP_INT(track->ff_index)},
20542060 {"hls-bitrate", SUB_PROP_INT(track->hls_bitrate),
20552061 .unavailable = !track->hls_bitrate},
@@ -2123,6 +2129,7 @@ static int get_track_entry(int item, int action, void *arg, void *ctx) · 67 unmodified lines
21232129 }
21242130
21252131 done:
2132+ talloc_free(external_filename);
21262133 talloc_free(tag_list);
21272134 return ret;
21282135 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t