diff options
author | Christoph Heinrich <christoph.heinrich@student.tugraz.at> | 2023-03-06 20:22:03 +0100 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2023-03-24 02:28:49 +0000 |
commit | 34a04d056764f4f1447d39b60be56f02253831f8 (patch) | |
tree | c6b33cb3d6a4576392c9d736c2b27359ec6a6bdf /player | |
parent | 5ddf6d479e7a109db660b991ecf545653d284320 (diff) | |
download | mpv-34a04d056764f4f1447d39b60be56f02253831f8.tar.bz2 mpv-34a04d056764f4f1447d39b60be56f02253831f8.tar.xz |
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.
Diffstat (limited to 'player')
-rw-r--r-- | player/command.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/player/command.c b/player/command.c index f115db6159..92e41e3bca 100644 --- a/player/command.c +++ b/player/command.c @@ -515,28 +515,34 @@ static int mp_property_file_size(void *ctx, struct m_property *prop, return m_property_int64_ro(action, arg, size); } -static int mp_property_media_title(void *ctx, struct m_property *prop, - int action, void *arg) +static const char *find_non_filename_media_title(MPContext *mpctx) { - MPContext *mpctx = ctx; - char *name = NULL; - if (mpctx->opts->media_title) - name = mpctx->opts->media_title; + const char *name = mpctx->opts->media_title; if (name && name[0]) - return m_property_strdup_ro(action, arg, name); + return 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); + return name; name = mp_tags_get_str(mpctx->demuxer->metadata, "title"); if (name && name[0]) - return m_property_strdup_ro(action, arg, name); + return name; name = mp_tags_get_str(mpctx->demuxer->metadata, "icy-title"); if (name && name[0]) - return m_property_strdup_ro(action, arg, name); + return name; } if (mpctx->playing && mpctx->playing->title) - return m_property_strdup_ro(action, arg, mpctx->playing->title); + return mpctx->playing->title; + return NULL; +} + +static int mp_property_media_title(void *ctx, struct m_property *prop, + int action, void *arg) +{ + MPContext *mpctx = ctx; + const char *name = find_non_filename_media_title(mpctx); + if (name && name[0]) + return m_property_strdup_ro(action, arg, name); return mp_property_filename(ctx, prop, action, arg); } @@ -6761,6 +6767,17 @@ static void command_event(struct MPContext *mpctx, int event, void *arg) if (event == MPV_EVENT_FILE_LOADED) audio_update_media_role(mpctx); + + if (event == MP_EVENT_METADATA_UPDATE) { + struct playlist_entry *const pe = mpctx->playing; + if (!pe->title) { + const char *const name = find_non_filename_media_title(mpctx); + if (name && name[0]) { + pe->title = talloc_strdup(pe, name); + mp_notify_property(mpctx, "playlist"); + } + } + } } void handle_command_updates(struct MPContext *mpctx) |