summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-02-19 16:29:04 +0100
committerwm4 <wm4@nowhere>2014-02-19 16:29:04 +0100
commitbda0e7da1376d5d190e972af794dd76bf83e56fe (patch)
tree1c371befe5a98f1876d788e99415a5293e464aca
parent844efa54313b395750d139abcea9425e9f4ee6f9 (diff)
downloadmpv-bda0e7da1376d5d190e972af794dd76bf83e56fe.tar.bz2
mpv-bda0e7da1376d5d190e972af794dd76bf83e56fe.tar.xz
command: allow accessing metadata entries as list
Not sure about these deep path-names. Maybe "metadata/0" should work instead of "metadata/list/0". I'm so unsure about it, that I'm leaving it open.
-rw-r--r--DOCS/man/en/input.rst12
-rw-r--r--player/command.c19
2 files changed, 31 insertions, 0 deletions
diff --git a/DOCS/man/en/input.rst b/DOCS/man/en/input.rst
index 4077d22e83..a004333a58 100644
--- a/DOCS/man/en/input.rst
+++ b/DOCS/man/en/input.rst
@@ -654,10 +654,22 @@ an option at runtime.
``metadata/by-key/<key>``
Value of metadata entry ``<key>``.
+ ``metadata/list/count``
+ Number of metadata entries.
+
+ ``metadata/list/N/name``
+ Key name of the Nth metadata entry. (The first entry is ``0``).
+
+ ``metadata/list/N/value``
+ Value of the Nth metadata entry.
+
``metadata/<key>``
Old version of ``metadata/by-key/<key>``. Use is discouraged, because
the metadata key string could conflict with other sub-properties.
+ The layout of this property might be subject to change. Suggestions are
+ welcome how exactly this property should work.
+
``chapter-metadata``
Metadata of current chapter. Works similar to ``metadata`` property. This
also allows referring to a key directly.
diff --git a/player/command.c b/player/command.c
index d9a2b99922..d9984fc8cb 100644
--- a/player/command.c
+++ b/player/command.c
@@ -770,6 +770,19 @@ static int mp_property_angle(m_option_t *prop, int action, void *arg,
return M_PROPERTY_NOT_IMPLEMENTED;
}
+static int get_tag_entry(int item, int action, void *arg, void *ctx)
+{
+ struct mp_tags *tags = ctx;
+
+ struct m_sub_property props[] = {
+ {"key", SUB_PROP_STR(tags->keys[item])},
+ {"value", SUB_PROP_STR(tags->values[item])},
+ {0}
+ };
+
+ return m_property_read_sub(props, action, arg);
+}
+
static int tag_property(m_option_t *prop, int action, void *arg,
struct mp_tags *tags)
{
@@ -802,6 +815,12 @@ static int tag_property(m_option_t *prop, int action, void *arg,
case M_PROPERTY_KEY_ACTION: {
struct m_property_action_arg *ka = arg;
bstr key = bstr0(ka->key);
+ if (bstr_eatstart0(&key, "list/")) {
+ struct m_property_action_arg nka = *ka;
+ nka.key = key.start; // ok because slice ends with \0
+ return m_property_read_list(action, &nka, tags->num_keys,
+ get_tag_entry, tags);
+ }
// Direct access without this prefix is allowed for compatibility.
bstr_eatstart0(&key, "by-key/");
char *meta = mp_tags_get_bstr(tags, key);