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. --- DOCS/man/options.rst | 8 ++++++++ common/tags.c | 19 +++++++++++++++++++ common/tags.h | 1 + options/options.c | 8 ++++++++ options/options.h | 1 + player/core.h | 2 +- player/loadfile.c | 13 +++++++------ 7 files changed, 45 insertions(+), 7 deletions(-) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 0feca9d765..e95f22aaeb 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -3187,6 +3187,14 @@ PVR Miscellaneous ------------- +``--display-tags=tag1,tags2,...`` + Set the list of tags that should be displayed on the terminal. Tags that + are in the list, but are not present in the played file, will not be shown. + The special value ``all`` disables filtering. + + The default includes a common list of tags, call mpv with ``--list-options`` + to see it. + ``--mc=`` Maximum A-V sync correction per frame (in seconds) 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, diff --git a/options/options.c b/options/options.c index 1eb687d1b2..8393971456 100644 --- a/options/options.c +++ b/options/options.c @@ -213,6 +213,8 @@ const m_option_t mp_opts[] = { OPT_CHOICE("hls-bitrate", hls_bitrate, M_OPT_FIXED, ({"no", 0}, {"min", 1}, {"max", 2})), + OPT_STRINGLIST("display-tags*", display_tags, 0), + #if HAVE_CDDA OPT_SUBSTRUCT("cdda", stream_cdda_opts, stream_cdda_conf, 0), OPT_STRING("cdrom-device", cdrom_device, M_OPT_FILE), @@ -778,6 +780,12 @@ const struct MPOpts mp_default_opts = { .dvd_angle = 1, .mf_fps = 1.0, + + .display_tags = (char **)(const char*[]){ + "artist", "album", "album_artist", "comment", "composer", "genre", + "performer", "title", "track", "icy-title", + NULL + }, }; #endif /* MPLAYER_CFG_MPLAYER_H */ diff --git a/options/options.h b/options/options.h index 21f7c100e6..5e24a20d1d 100644 --- a/options/options.h +++ b/options/options.h @@ -180,6 +180,7 @@ typedef struct MPOpts { char **audio_lang; char **sub_lang; int audio_display; + char **display_tags; int sub_visibility; int sub_pos; float sub_delay; diff --git a/player/core.h b/player/core.h index 8184b133ce..a28d2e169f 100644 --- a/player/core.h +++ b/player/core.h @@ -196,7 +196,7 @@ typedef struct MPContext { double video_offset; struct demuxer *demuxer; - struct mp_tags *tags; + struct mp_tags *filtered_tags; struct track **tracks; int num_tracks; diff --git a/player/loadfile.c b/player/loadfile.c index 2f75a5bea9..96e34f5a95 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -168,9 +168,10 @@ void update_demuxer_properties(struct MPContext *mpctx) tracks->events &= ~DEMUX_EVENT_STREAMS; } if (events & DEMUX_EVENT_METADATA) { - struct mp_tags *info = demuxer->metadata; + struct mp_tags *info = + mp_tags_filtered(mpctx, demuxer->metadata, mpctx->opts->display_tags); // prev is used to attempt to print changed tags only (to some degree) - struct mp_tags *prev = mpctx->tags; + struct mp_tags *prev = mpctx->filtered_tags; int n_prev = 0; bool had_output = false; for (int n = 0; n < info->num_keys; n++) { @@ -186,8 +187,8 @@ void update_demuxer_properties(struct MPContext *mpctx) MP_INFO(mpctx, " %s: %s\n", info->keys[n], info->values[n]); had_output = true; } - talloc_free(mpctx->tags); - mpctx->tags = mp_tags_dup(mpctx, info); + talloc_free(mpctx->filtered_tags); + mpctx->filtered_tags = info; mp_notify(mpctx, MPV_EVENT_METADATA_UPDATE, NULL); } demuxer->events = 0; @@ -1223,8 +1224,8 @@ terminate_playback: m_config_restore_backups(mpctx->mconfig); - talloc_free(mpctx->tags); - mpctx->tags = NULL; + talloc_free(mpctx->filtered_tags); + mpctx->filtered_tags = NULL; mpctx->playback_initialized = false; -- cgit v1.2.3