summaryrefslogtreecommitdiffstats
path: root/common/tags.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/tags.c')
-rw-r--r--common/tags.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/common/tags.c b/common/tags.c
index bc9d98ea2f..c38d002243 100644
--- a/common/tags.c
+++ b/common/tags.c
@@ -74,6 +74,25 @@ struct mp_tags *mp_tags_dup(void *tparent, struct mp_tags *tags)
return new;
}
+// Return a copy of the tags, but containing only keys in list. Also forces
+// the order and casing of the keys (for cosmetic reasons).
+// The special key "all" matches all keys.
+struct mp_tags *mp_tags_filtered(void *tparent, struct mp_tags *tags, char **list)
+{
+ struct mp_tags *new = talloc_zero(tparent, struct mp_tags);
+ for (int n = 0; list && list[n]; n++) {
+ char *key = list[n];
+ if (strcasecmp(key, "all") == 0) {
+ talloc_free(new);
+ return mp_tags_dup(tparent, tags);
+ }
+ char *value = mp_tags_get_str(tags, key);
+ if (value)
+ mp_tags_set_str(new, key, value);
+ }
+ return new;
+}
+
void mp_tags_merge(struct mp_tags *tags, struct mp_tags *src)
{
for (int n = 0; n < src->num_keys; n++)