From 048d4d8b7556f06afb46e7e94852709a1a624aed Mon Sep 17 00:00:00 2001 From: Christoph Heinrich Date: Tue, 26 Jul 2022 18:05:36 +0200 Subject: [PATCH] player: set playlist title to media title if not set already The playlist title only got set when it was specified in the playlist file. If there is a title after opening a file, that should also be reflected in the playlist. ref. #4780 --- DOCS/man/input.rst | 7 ++++--- player/command.c | 31 +++++++++++++++++-------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 47cb9430cd..ea305af615 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -2789,9 +2789,10 @@ Property list entry, ``no``/false or unavailable otherwise. ``playlist/N/title`` - Name of the Nth entry. Only available if the playlist file contains - such fields, and only if mpv's parser supports it for the given - playlist format. + Name of the Nth entry. Available if the playlist file contains + such fields and mpv's parser supports it for the given + playlist format, or if the playlist entry has been opened before and a + media-title other then then filename has been aquired. ``playlist/N/id`` Unique ID for this entry. This is an automatically assigned integer ID diff --git a/player/command.c b/player/command.c index 9d6ef4fa54..2ad83cb703 100644 --- a/player/command.c +++ b/player/command.c @@ -519,24 +519,27 @@ static int mp_property_media_title(void *ctx, struct m_property *prop, int action, void *arg) { MPContext *mpctx = ctx; - char *name = NULL; + const char* name = NULL; if (mpctx->opts->media_title) name = mpctx->opts->media_title; + if ((!name || !name[0]) && mpctx->demuxer) { + name = mp_tags_get_str(mpctx->demuxer->metadata, "service_name"); + if (!name || !name[0]){ + name = mp_tags_get_str(mpctx->demuxer->metadata, "title"); + if (!name || !name[0]) + name = mp_tags_get_str(mpctx->demuxer->metadata, "icy-title"); + } + } + struct playlist_entry *const pe = mpctx->playing; + if (pe) { + if (!name || !name[0]){ + name = pe->title; + } else if (!pe->title) { + pe->title = talloc_strdup(pe, name); + } + } if (name && name[0]) return m_property_strdup_ro(action, arg, name); - if (mpctx->demuxer) { - name = mp_tags_get_str(mpctx->demuxer->metadata, "service_name"); - if (name && name[0]) - return m_property_strdup_ro(action, arg, name); - name = mp_tags_get_str(mpctx->demuxer->metadata, "title"); - if (name && name[0]) - return m_property_strdup_ro(action, arg, name); - name = mp_tags_get_str(mpctx->demuxer->metadata, "icy-title"); - if (name && name[0]) - return m_property_strdup_ro(action, arg, name); - } - if (mpctx->playing && mpctx->playing->title) - return m_property_strdup_ro(action, arg, mpctx->playing->title); return mp_property_filename(ctx, prop, action, arg); }