History

command: add metadata sub-property for track-list

Requires a little bit of massaging for the key/value access to work correctly, it's not terribly intrusive all things considered.

Dudemanguy committed 1 year ago

Commit 814316f1 parent 5c326264 files · +44 −1Browse files

Unified · Split

4 files
  1. DOCS/interface-changes/track-metadata.txt +1 −0
  2. DOCS/man/input.rst +6 −0
  3. options/m_property.h +2 −0
  4. player/command.c +35 −1
DOCS/interface-changes/track-metadata.txt+1−0
@@ -0,0 +1 @@
1+add `metadata` sub-property for `track-list`
DOCS/man/input.rst+6−0
@@ -3373,6 +3373,10 @@ Property list · 3372 unmodified lines
33733373 Dolby Vision profile and level. May not be available if the container
33743374 does not provide this information.
33753375
3376+ ``track-list/N/metadata``,
3377+ Works like the ``metadata`` property, but it accesses metadata that is
3378+ set per track/stream instead of global values for the entire file.
3379+
33763380 When querying the property with the client API using ``MPV_FORMAT_NODE``,
33773381 or with Lua ``mp.get_property_native``, this will return a mpv_node with
33783382 the following contents:
@@ -3426,6 +3430,8 @@ Property list · 47 unmodified lines
34263430 "replaygain-album-gain" MPV_FORMAT_DOUBLE
34273431 "dolby-vision-profile" MPV_FORMAT_INT64
34283432 "dolby-vision-level" MPV_FORMAT_INT64
3433+ "metadata" MPV_FORMAT_NODE_MAP
3434+ (key and string value for each metadata entry)
34293435
34303436 ``current-tracks/...``
34313437 This gives access to currently selected tracks. It redirects to the correct
options/m_property.h+2−0
@@ -220,6 +220,8 @@ struct m_sub_property { · 219 unmodified lines
220220 .type = {.type = CONF_TYPE_BOOL}, .value = {.bool_ = (f)}
221221 #define SUB_PROP_PTS(f) \
222222 .type = {.type = &m_option_type_time}, .value = {.double_ = (f)}
223+#define SUB_PROP_KEYVALUE_LIST(l) \
224+ .type = {.type = &m_option_type_keyvalue_list}, .value = {.keyvalue_list = (l)}
223225
224226 int m_property_read_sub_validate(void *ctx, struct m_property *prop,
225227 int action, void *arg);
player/command.c+35−1
@@ -2004,6 +2004,13 @@ static int get_track_entry(int item, int action, void *arg, void *ctx) · 2003 unmodified lines
20042004 struct replaygain_data rg = has_rg ? *track->stream->codec->replaygain_data
20052005 : (struct replaygain_data){0};
20062006
2007+ struct mp_tags *tags = track->stream ? track->stream->tags : &(struct mp_tags){0};
2008+ char **tag_list = talloc_zero_array(NULL, char *, tags->num_keys * 2 + 1);
2009+ for (int i = 0; i < tags->num_keys; i++) {
2010+ tag_list[2 * i] = talloc_strdup(tag_list, tags->keys[i]);
2011+ tag_list[2 * i + 1] = talloc_strdup(tag_list, tags->values[i]);
2012+ }
2013+
20072014 double par = 0.0;
20082015 if (p.par_h)
20092016 par = p.par_w / (double) p.par_h;
@@ -2087,10 +2094,37 @@ static int get_track_entry(int item, int action, void *arg, void *ctx) · 77 unmodified lines
20872094 .unavailable = !p.dovi},
20882095 {"dolby-vision-level", SUB_PROP_INT(p.dv_level),
20892096 .unavailable = !p.dovi},
2097+ {"metadata", SUB_PROP_KEYVALUE_LIST(tag_list),
2098+ .unavailable = !tags->num_keys},
20902099 {0}
20912100 };
20922101
2093− return m_property_read_sub(props, action, arg);
2102+ int ret = 0;
2103+ switch (action) {
2104+ case M_PROPERTY_KEY_ACTION: ;
2105+ struct m_property_action_arg *ka = arg;
2106+ if (!strncmp(ka->key, "metadata/", 9)) {
2107+ bstr key = {0};
2108+ char *rem = "";
2109+ m_property_split_path(ka->key, &key, &rem);
2110+ ka->key = !rem[0] ? "metadata" : rem;
2111+ if (rem[0]) {
2112+ if (!tags || tags->num_keys == 0) {
2113+ ret = M_PROPERTY_UNAVAILABLE;
2114+ } else {
2115+ ret = tag_property(action, (void *)ka, tags);
2116+ }
2117+ goto done;
2118+ }
2119+ }
2120+ MP_FALLTHROUGH;
2121+ default:
2122+ ret = m_property_read_sub(props, action, arg);
2123+ }
2124+
2125+done:
2126+ talloc_free(tag_list);
2127+ return ret;
20942128 }
20952129
20962130 static const char *track_type_name(struct track *t)

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