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
This commit is contained in:
Christoph Heinrich 2022-07-26 18:05:36 +02:00 committed by Dudemanguy
parent ed5426c351
commit 048d4d8b75
2 changed files with 21 additions and 17 deletions

View File

@ -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

View File

@ -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);
}