summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-03-27 00:57:11 +0100
committerwm4 <wm4@nowhere>2020-03-27 00:57:11 +0100
commitdf0d8cda08463b291203812ec475ca185bc8e947 (patch)
treebd10780993e10b5fbc089f1b9bb2019a830d4a3f /player
parentd3be6a61634ff6f9ba217320eaa9fb9349a5c144 (diff)
downloadmpv-df0d8cda08463b291203812ec475ca185bc8e947.tar.bz2
mpv-df0d8cda08463b291203812ec475ca185bc8e947.tar.xz
client API: report IDs of inserted playlist entries on loading playlist
May or may not help when dealing with playlist loading in scripts. It's supposed to help with the mean fact that loading a recursive playlist will essentially edit the playlist behind the API user's back.
Diffstat (limited to 'player')
-rw-r--r--player/client.c6
-rw-r--r--player/loadfile.c15
2 files changed, 15 insertions, 6 deletions
diff --git a/player/client.c b/player/client.c
index d2a94cc0c9..0babacf147 100644
--- a/player/client.c
+++ b/player/client.c
@@ -1979,6 +1979,12 @@ int mpv_event_to_node(mpv_node *dst, mpv_event *event)
node_map_add_int64(dst, "playlist_entry_id", eef->playlist_entry_id);
+ if (eef->playlist_insert_id) {
+ node_map_add_int64(dst, "playlist_insert_id", eef->playlist_insert_id);
+ node_map_add_int64(dst, "playlist_insert_num_entries",
+ eef->playlist_insert_num_entries);
+ }
+
if (eef->reason == MPV_END_FILE_REASON_ERROR)
node_map_add_string(dst, "file_error", mpv_error_string(eef->error));
break;
diff --git a/player/loadfile.c b/player/loadfile.c
index 46627a9b23..9efacea766 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -906,14 +906,16 @@ void prepare_playlist(struct MPContext *mpctx, struct playlist *pl)
// Replace the current playlist entry with playlist contents. Moves the entries
// from the given playlist pl, so the entries don't actually need to be copied.
-static void transfer_playlist(struct MPContext *mpctx, struct playlist *pl)
+static void transfer_playlist(struct MPContext *mpctx, struct playlist *pl,
+ int64_t *start_id, int *num_new_entries)
{
if (pl->num_entries) {
prepare_playlist(mpctx, pl);
struct playlist_entry *new = pl->current;
if (mpctx->playlist->current)
playlist_add_redirect(pl, mpctx->playlist->current->filename);
- playlist_transfer_entries(mpctx->playlist, pl);
+ *num_new_entries = pl->num_entries;
+ *start_id = playlist_transfer_entries(mpctx->playlist, pl);
// current entry is replaced
if (mpctx->playlist->current)
playlist_remove(mpctx->playlist, mpctx->playlist->current);
@@ -1384,6 +1386,9 @@ static void play_current_file(struct MPContext *mpctx)
mpv_event_start_file start_event = {
.playlist_entry_id = mpctx->playlist->current->id,
};
+ mpv_event_end_file end_event = {
+ .playlist_entry_id = start_event.playlist_entry_id,
+ };
mp_notify(mpctx, MPV_EVENT_START_FILE, &start_event);
@@ -1477,7 +1482,8 @@ static void play_current_file(struct MPContext *mpctx)
if (mpctx->demuxer->playlist) {
struct playlist *pl = mpctx->demuxer->playlist;
- transfer_playlist(mpctx, pl);
+ transfer_playlist(mpctx, pl, &end_event.playlist_insert_id,
+ &end_event.playlist_insert_num_entries);
mp_notify_property(mpctx, "playlist");
mpctx->error_playing = 2;
goto terminate_playback;
@@ -1657,9 +1663,6 @@ terminate_playback:
bool nothing_played = !mpctx->shown_aframes && !mpctx->shown_vframes &&
mpctx->error_playing <= 0;
- struct mpv_event_end_file end_event = {
- .playlist_entry_id = start_event.playlist_entry_id,
- };
switch (mpctx->stop_play) {
case PT_ERROR:
case AT_END_OF_FILE: