diff options
author | Dudemanguy <random342@airmail.cc> | 2023-08-10 23:27:28 -0500 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2023-08-13 19:58:20 +0000 |
commit | e8a77e5279c2682a1554ba8fd47b99c6bf6f4d52 (patch) | |
tree | 43931c6983b6a8614bc2f147b5595b15b10b7a2f /player | |
parent | a177fb6188e735da3536109105ec55a51b3b863c (diff) | |
download | mpv-e8a77e5279c2682a1554ba8fd47b99c6bf6f4d52.tar.bz2 mpv-e8a77e5279c2682a1554ba8fd47b99c6bf6f4d52.tar.xz |
player: add playlist-path properties
A bit of a long standing pain with scripting is that when opening a file
that gets interpreted as a playlist (like an m3u), the original path of
the file gets thrown away later. Workarounds basically consist of
getting the filename before mpv expands the path, but that's not really
reliable. Instead of throwing it away, save the original playlist path
by copying to the playlist entries when applicable (demuxer playlist and
the playlist option). Then expose these as properties: playlist-path for
the currently playing entry and playlist/N/playlist-path for each
specific entry. Closes #8508, #7605.
Diffstat (limited to 'player')
-rw-r--r-- | player/command.c | 23 | ||||
-rw-r--r-- | player/loadfile.c | 1 |
2 files changed, 19 insertions, 5 deletions
diff --git a/player/command.c b/player/command.c index 28c97f0d6f..a00b42ca8c 100644 --- a/player/command.c +++ b/player/command.c @@ -3092,17 +3092,29 @@ static int get_playlist_entry(int item, int action, void *arg, void *ctx) bool current = mpctx->playlist->current == e; bool playing = mpctx->playing == e; struct m_sub_property props[] = { - {"filename", SUB_PROP_STR(e->filename)}, - {"current", SUB_PROP_BOOL(1), .unavailable = !current}, - {"playing", SUB_PROP_BOOL(1), .unavailable = !playing}, - {"title", SUB_PROP_STR(e->title), .unavailable = !e->title}, - {"id", SUB_PROP_INT64(e->id)}, + {"filename", SUB_PROP_STR(e->filename)}, + {"current", SUB_PROP_BOOL(1), .unavailable = !current}, + {"playing", SUB_PROP_BOOL(1), .unavailable = !playing}, + {"title", SUB_PROP_STR(e->title), .unavailable = !e->title}, + {"id", SUB_PROP_INT64(e->id)}, + {"playlist-path", SUB_PROP_STR(e->playlist_path), .unavailable = !e->playlist_path}, {0} }; return m_property_read_sub(props, action, arg); } +static int mp_property_playlist_path(void *ctx, struct m_property *prop, + int action, void *arg) +{ + MPContext *mpctx = ctx; + if (!mpctx->playlist->current) + return M_PROPERTY_UNAVAILABLE; + + struct playlist_entry *e = mpctx->playlist->current; + return m_property_strdup_ro(action, arg, e->playlist_path); +} + static int mp_property_playlist(void *ctx, struct m_property *prop, int action, void *arg) { @@ -3875,6 +3887,7 @@ static const struct m_property mp_properties_base[] = { {"edition-list", property_list_editions}, {"playlist", mp_property_playlist}, + {"playlist-path", mp_property_playlist_path}, {"playlist-pos", mp_property_playlist_pos}, {"playlist-pos-1", mp_property_playlist_pos_1}, {"playlist-current-pos", mp_property_playlist_current_pos}, diff --git a/player/loadfile.c b/player/loadfile.c index 851413bb06..a2f593333e 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -1659,6 +1659,7 @@ static void play_current_file(struct MPContext *mpctx) if (watch_later) mp_delete_watch_later_conf(mpctx, mpctx->filename); struct playlist *pl = mpctx->demuxer->playlist; + playlist_populate_playlist_path(pl, mpctx->filename); transfer_playlist(mpctx, pl, &end_event.playlist_insert_id, &end_event.playlist_insert_num_entries); mp_notify_property(mpctx, "playlist"); |