summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/tags.c19
-rw-r--r--common/tags.h1
2 files changed, 20 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++)
diff --git a/common/tags.h b/common/tags.h
index b6db5f3df2..dc8539d98f 100644
--- a/common/tags.h
+++ b/common/tags.h
@@ -15,6 +15,7 @@ char *mp_tags_get_str(struct mp_tags *tags, const char *key);
char *mp_tags_get_bstr(struct mp_tags *tags, bstr key);
void mp_tags_clear(struct mp_tags *tags);
struct mp_tags *mp_tags_dup(void *tparent, struct mp_tags *tags);
+struct mp_tags *mp_tags_filtered(void *tparent, struct mp_tags *tags, char **list);
void mp_tags_merge(struct mp_tags *tags, struct mp_tags *src);
struct AVDictionary;
void mp_tags_copy_from_av_dictionary(struct mp_tags *tags,