From 8048374a5c1eb3af80aa057dcfd20deed39447c8 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 29 Dec 2014 22:51:18 +0100 Subject: player: filter tags, add --display-tags option This attempts to increase user-friendliness by excluding useless tags. It should be especially helpful with mp4 files, because the FFmpeg mp4 demuxer adds tons of completely useless information to the metadata. Fixes #1403. --- common/tags.c | 19 +++++++++++++++++++ common/tags.h | 1 + 2 files changed, 20 insertions(+) (limited to 'common') 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, -- cgit v1.2.3