mirror of
https://github.com/mpv-player/mpv
synced 2025-04-10 11:41:37 +00:00
command: add a way to access properties of a current track
Requested. Should be good for simple use cases. "sub2" is technically inconsistent (since the option is called --secondary-sid), but fuck the consistent name.
This commit is contained in:
parent
45cc47a68b
commit
720bcd79d0
@ -2780,6 +2780,26 @@ Property list
|
|||||||
"replaygain-album-peak" MPV_FORMAT_DOUBLE
|
"replaygain-album-peak" MPV_FORMAT_DOUBLE
|
||||||
"replaygain-album-gain" MPV_FORMAT_DOUBLE
|
"replaygain-album-gain" MPV_FORMAT_DOUBLE
|
||||||
|
|
||||||
|
``current-tracks/...``
|
||||||
|
This gives access to currently selected tracks. It redirects to the correct
|
||||||
|
entry in ``track-list``.
|
||||||
|
|
||||||
|
The following sub-entries are defined: ``video``, ``audio``, ``sub``,
|
||||||
|
``sub2``
|
||||||
|
|
||||||
|
For example, ``current-tracks/audio/lang`` returns the current audio track's
|
||||||
|
language field (the same value as ``track-list/N/lang``).
|
||||||
|
|
||||||
|
A sub-entry is accessible only if a track of that type is actually selected.
|
||||||
|
Tracks selected via ``--lavfi-complex`` never appear under this property.
|
||||||
|
``current-tracks`` and ``current-tracks/`` are currently not accessible, and
|
||||||
|
will not return anything.
|
||||||
|
|
||||||
|
Scripts etc. should not use this. They should use ``track-list``, loop over
|
||||||
|
all tracks, and inspect the ``selected`` field to test whether a track is
|
||||||
|
selected (or compare the ``id`` field to the ``video`` / ``audio`` etc.
|
||||||
|
options).
|
||||||
|
|
||||||
``chapter-list``
|
``chapter-list``
|
||||||
List of chapters, current entry marked. Currently, the raw property value
|
List of chapters, current entry marked. Currently, the raw property value
|
||||||
is useless.
|
is useless.
|
||||||
|
@ -2025,6 +2025,53 @@ static int property_list_tracks(void *ctx, struct m_property *prop,
|
|||||||
get_track_entry, mpctx);
|
get_track_entry, mpctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int property_current_tracks(void *ctx, struct m_property *prop,
|
||||||
|
int action, void *arg)
|
||||||
|
{
|
||||||
|
MPContext *mpctx = ctx;
|
||||||
|
|
||||||
|
if (action != M_PROPERTY_KEY_ACTION)
|
||||||
|
return M_PROPERTY_UNAVAILABLE;
|
||||||
|
|
||||||
|
int type = -1;
|
||||||
|
int order = 0;
|
||||||
|
|
||||||
|
struct m_property_action_arg *ka = arg;
|
||||||
|
bstr key;
|
||||||
|
char *rem;
|
||||||
|
m_property_split_path(ka->key, &key, &rem);
|
||||||
|
|
||||||
|
if (bstr_equals0(key, "video")) {
|
||||||
|
type = STREAM_VIDEO;
|
||||||
|
} else if (bstr_equals0(key, "audio")) {
|
||||||
|
type = STREAM_AUDIO;
|
||||||
|
} else if (bstr_equals0(key, "sub")) {
|
||||||
|
type = STREAM_SUB;
|
||||||
|
} else if (bstr_equals0(key, "sub2")) {
|
||||||
|
type = STREAM_SUB;
|
||||||
|
order = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type < 0)
|
||||||
|
return M_PROPERTY_UNKNOWN;
|
||||||
|
|
||||||
|
struct track *t = mpctx->current_track[order][type];
|
||||||
|
if (!t)
|
||||||
|
return M_PROPERTY_UNAVAILABLE;
|
||||||
|
|
||||||
|
int index = -1;
|
||||||
|
for (int n = 0; n < mpctx->num_tracks; n++) {
|
||||||
|
if (mpctx->tracks[n] == t) {
|
||||||
|
index = n;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(index >= 0);
|
||||||
|
|
||||||
|
char *name = mp_tprintf(80, "track-list/%d/%s", index, rem);
|
||||||
|
return mp_property_do(name, ka->action, ka->arg, ctx);
|
||||||
|
}
|
||||||
|
|
||||||
static int mp_property_hwdec_current(void *ctx, struct m_property *prop,
|
static int mp_property_hwdec_current(void *ctx, struct m_property *prop,
|
||||||
int action, void *arg)
|
int action, void *arg)
|
||||||
{
|
{
|
||||||
@ -3445,6 +3492,7 @@ static const struct m_property mp_properties_base[] = {
|
|||||||
|
|
||||||
{"chapter-list", mp_property_list_chapters},
|
{"chapter-list", mp_property_list_chapters},
|
||||||
{"track-list", property_list_tracks},
|
{"track-list", property_list_tracks},
|
||||||
|
{"current-tracks", property_current_tracks},
|
||||||
{"edition-list", property_list_editions},
|
{"edition-list", property_list_editions},
|
||||||
|
|
||||||
{"playlist", mp_property_playlist},
|
{"playlist", mp_property_playlist},
|
||||||
@ -3584,7 +3632,7 @@ static const char *const *const mp_event_property_change[] = {
|
|||||||
E(MPV_EVENT_END_FILE, "*"),
|
E(MPV_EVENT_END_FILE, "*"),
|
||||||
E(MPV_EVENT_FILE_LOADED, "*"),
|
E(MPV_EVENT_FILE_LOADED, "*"),
|
||||||
E(MP_EVENT_CHANGE_ALL, "*"),
|
E(MP_EVENT_CHANGE_ALL, "*"),
|
||||||
E(MPV_EVENT_TRACKS_CHANGED, "track-list"),
|
E(MPV_EVENT_TRACKS_CHANGED, "track-list", "current-tracks"),
|
||||||
E(MPV_EVENT_IDLE, "*"),
|
E(MPV_EVENT_IDLE, "*"),
|
||||||
E(MPV_EVENT_TICK, "time-pos", "audio-pts", "stream-pos", "avsync",
|
E(MPV_EVENT_TICK, "time-pos", "audio-pts", "stream-pos", "avsync",
|
||||||
"percent-pos", "time-remaining", "playtime-remaining", "playback-time",
|
"percent-pos", "time-remaining", "playtime-remaining", "playback-time",
|
||||||
|
Loading…
Reference in New Issue
Block a user