command: export list of editions as properties

This commit is contained in:
wm4 2014-02-19 00:41:12 +01:00
parent dc0636102c
commit 283139607c
2 changed files with 83 additions and 0 deletions

View File

@ -619,6 +619,28 @@ an option at runtime.
``editions``
Number of MKV editions.
``edition-list``
List of editions, current entry marked. Currently, the raw property value
is useless.
This has a number of sub-properties. Replace ``N`` with the 0-based edition
index.
``edition-list/count``
Number of editions. If there are no editions, this can be 0 or 1 (1
if there's a useless dummy edition).
``edition-list/N/id``
Edition ID as integer. Use this to set the ``edition`` property.
Currently, this is the same as the edition index.
``edition-list/N/default``
``yes`` if this is the default edition, ``no`` otherwise.
``edition-list/N/title``
Edition title as stored in the file. Not always available.
``angle`` (RW)
Current DVD angle.

View File

@ -556,6 +556,66 @@ static int mp_property_edition(m_option_t *prop, int action, void *arg,
return M_PROPERTY_NOT_IMPLEMENTED;
}
static int get_edition_entry(int item, int action, void *arg, void *ctx)
{
struct MPContext *mpctx = ctx;
struct demuxer *demuxer = mpctx->master_demuxer;
struct demux_edition *ed = &demuxer->editions[item];
char *title = mp_tags_get_str(ed->metadata, "title");
struct m_sub_property props[] = {
{"id", SUB_PROP_INT(item)},
{"title", SUB_PROP_STR(title),
.unavailable = !title},
{"default", SUB_PROP_FLAG(ed->default_edition)},
{0}
};
return m_property_read_sub(props, action, arg);
}
static int property_list_editions(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
struct demuxer *demuxer = mpctx->master_demuxer;
if (!demuxer)
return M_PROPERTY_UNAVAILABLE;
if (action == M_PROPERTY_PRINT) {
char *res = NULL;
struct demux_edition *editions = demuxer->editions;
int num_editions = demuxer->num_editions;
int current = demuxer->edition;
if (!num_editions)
res = talloc_asprintf_append(res, "No editions.");
for (int n = 0; n < num_editions; n++) {
struct demux_edition *ed = &editions[n];
if (n == current)
res = talloc_asprintf_append(res, "> ");
res = talloc_asprintf_append(res, "%d: ", n);
char *title = mp_tags_get_str(ed->metadata, "title");
if (!title)
title = "unnamed";
res = talloc_asprintf_append(res, "'%s' ", title);
if (n == current)
res = talloc_asprintf_append(res, "<");
res = talloc_asprintf_append(res, "\n");
}
*(char **)arg = res;
return M_PROPERTY_OK;
}
return m_property_read_list(action, arg, demuxer->num_editions,
get_edition_entry, mpctx);
}
static struct mp_resolve_src *find_source(struct mp_resolve_result *res,
char *encid, char *url)
{
@ -2009,6 +2069,7 @@ static const m_option_t mp_properties[] = {
M_PROPERTY("chapter-list", mp_property_list_chapters),
M_PROPERTY("track-list", property_list_tracks),
M_PROPERTY("edition-list", property_list_editions),
M_PROPERTY("playlist", mp_property_playlist),
{ "playlist-pos", mp_property_playlist_pos, CONF_TYPE_INT },