command: implement printing ${track-list/{video,audio,sub}}

This brings show-text ${track-list} in line with osc.lua's
get_tracklist(type) before replacing it with show-text.
This commit is contained in:
Guido Cella 2024-10-11 19:55:38 +02:00 committed by Kacper Michajłow
parent 89d78369c6
commit 3522dd836e
2 changed files with 69 additions and 15 deletions

View File

@ -3098,6 +3098,18 @@ Property list
``track-list/count``
Total number of tracks.
``track-list/video``
The list of video tracks. This is only usable for printing and its value
can't be retrieved.
``track-list/audio``
The list of audio tracks. This is only usable for printing and its value
can't be retrieved.
``track-list/sub``
The list of sub tracks. This is only usable for printing and its value
can't be retrieved.
``track-list/N/id``
The ID as it's used for ``--sid``/``--aid``/``--vid``. This is unique
within tracks of the same type (sub/audio/video), but otherwise not.

View File

@ -2104,6 +2104,22 @@ static const char *track_type_name(struct track *t)
return NULL;
}
static char *append_track_info(char *res, struct track *track)
{
res = talloc_strdup_append(res, track->selected ? list_current : list_normal);
res = talloc_asprintf_append(res, "(%d) ", track->user_tid);
if (track->title)
res = talloc_asprintf_append(res, "'%s' ", track->title);
if (track->lang)
res = talloc_asprintf_append(res, "(%s) ", track->lang);
if (track->is_external)
res = talloc_asprintf_append(res, "(external) ");
res = talloc_asprintf_append(res, "\n");
return res;
}
static int property_list_tracks(void *ctx, struct m_property *prop,
int action, void *arg)
{
@ -2114,21 +2130,10 @@ static int property_list_tracks(void *ctx, struct m_property *prop,
for (int type = 0; type < STREAM_TYPE_COUNT; type++) {
for (int n = 0; n < mpctx->num_tracks; n++) {
struct track *track = mpctx->tracks[n];
if (track->type != type)
continue;
res = talloc_asprintf_append(res, "%s: ",
track_type_name(track));
res = talloc_strdup_append(res,
track->selected ? list_current : list_normal);
res = talloc_asprintf_append(res, "(%d) ", track->user_tid);
if (track->title)
res = talloc_asprintf_append(res, "'%s' ", track->title);
if (track->lang)
res = talloc_asprintf_append(res, "(%s) ", track->lang);
if (track->is_external)
res = talloc_asprintf_append(res, "(external) ");
res = talloc_asprintf_append(res, "\n");
if (track->type == type) {
res = talloc_asprintf_append(res, "%s: ", track_type_name(track));
res = append_track_info(res, track);
}
}
res = talloc_asprintf_append(res, "\n");
@ -2143,6 +2148,43 @@ static int property_list_tracks(void *ctx, struct m_property *prop,
*(char **)arg = res;
return M_PROPERTY_OK;
}
if (action == M_PROPERTY_KEY_ACTION) {
struct m_property_action_arg *ka = arg;
int type = -1;
if (!strcmp(ka->key, "video")) {
type = STREAM_VIDEO;
} else if (!strcmp(ka->key, "audio")) {
type = STREAM_AUDIO;
} else if (!strcmp(ka->key, "sub")) {
type = STREAM_SUB;
}
if (type != -1) {
char *res;
switch (ka->action) {
case M_PROPERTY_GET_TYPE:
*(struct m_option *)ka->arg = (struct m_option){.type = CONF_TYPE_STRING};
return M_PROPERTY_OK;
case M_PROPERTY_PRINT:
res = talloc_asprintf(NULL, "Available %s tracks:\n",
type == STREAM_SUB ? "subtitle" : stream_type_name(type));
for (int n = 0; n < mpctx->num_tracks; n++) {
if (mpctx->tracks[n]->type == type)
res = append_track_info(res, mpctx->tracks[n]);
}
*(char **)ka->arg = res;
return M_PROPERTY_OK;
default:
return M_PROPERTY_NOT_IMPLEMENTED;
}
}
}
return m_property_read_list(action, arg, mpctx->num_tracks,
get_track_entry, mpctx);
}