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 @@
1the `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
2109 Process-id of mpv.2109 Process-id of mpv.
2110 2110
2111``path``2111``path``
2112 Full path of the currently played file. Usually this is exactly the same2112 Full absolute path of the currently played file.
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.
2116 2113
2117``stream-open-filename``2114``stream-open-filename``
2118 The full path to the currently played media. This is different from2115 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
507 MPContext *mpctx = ctx;507 MPContext *mpctx = ctx;
508 if (!mpctx->filename)508 if (!mpctx->filename)
509 return M_PROPERTY_UNAVAILABLE;509 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;
511}514}
512 515
513static int mp_property_filename(void *ctx, struct m_property *prop,516static 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
1997 struct MPContext *mpctx = ctx;2000 struct MPContext *mpctx = ctx;
1998 struct track *track = mpctx->tracks[item];2001 struct track *track = mpctx->tracks[item];
1999 2002
2003 char *external_filename = mp_normalize_user_path(NULL, mpctx->global,
2004 track->external_filename);
2005
2000 struct mp_codec_params p =2006 struct mp_codec_params p =
2001 track->stream ? *track->stream->codec : (struct mp_codec_params){0};2007 track->stream ? *track->stream->codec : (struct mp_codec_params){0};
2002 2008
@@ -2048,8 +2054,8 @@ static int get_track_entry(int item, int action, void *arg, void *ctx) · 45 unmodified lines
2048 {"external", SUB_PROP_BOOL(track->is_external)},2054 {"external", SUB_PROP_BOOL(track->is_external)},
2049 {"selected", SUB_PROP_BOOL(track->selected)},2055 {"selected", SUB_PROP_BOOL(track->selected)},
2050 {"main-selection", SUB_PROP_INT(order), .unavailable = order < 0},2056 {"main-selection", SUB_PROP_INT(order), .unavailable = order < 0},
2051 {"external-filename", SUB_PROP_STR(track->external_filename),2057 {"external-filename", SUB_PROP_STR(external_filename),
2052 .unavailable = !track->external_filename},2058 .unavailable = !external_filename},
2053 {"ff-index", SUB_PROP_INT(track->ff_index)},2059 {"ff-index", SUB_PROP_INT(track->ff_index)},
2054 {"hls-bitrate", SUB_PROP_INT(track->hls_bitrate),2060 {"hls-bitrate", SUB_PROP_INT(track->hls_bitrate),
2055 .unavailable = !track->hls_bitrate},2061 .unavailable = !track->hls_bitrate},
@@ -2123,6 +2129,7 @@ static int get_track_entry(int item, int action, void *arg, void *ctx) · 67 unmodified lines
2123 }2129 }
2124 2130
2125done:2131done:
2132 talloc_free(external_filename);
2126 talloc_free(tag_list);2133 talloc_free(tag_list);
2127 return ret;2134 return ret;
2128}2135}

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