summaryrefslogtreecommitdiffstats
path: root/common/playlist.c
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 /common/playlist.c
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 'common/playlist.c')
-rw-r--r--common/playlist.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/common/playlist.c b/common/playlist.c
index d7c752ad8d..b7398dd936 100644
--- a/common/playlist.c
+++ b/common/playlist.c
@@ -239,10 +239,11 @@ void playlist_set_stream_flags(struct playlist *pl, int flags)
pl->entries[n]->stream_flags = flags;
}
-static void playlist_transfer_entries_to(struct playlist *pl, int dst_index,
- struct playlist *source_pl)
+static int64_t playlist_transfer_entries_to(struct playlist *pl, int dst_index,
+ struct playlist *source_pl)
{
assert(pl != source_pl);
+ struct playlist_entry *first = playlist_get_first(source_pl);
int count = source_pl->num_entries;
MP_TARRAY_INSERT_N_AT(pl, pl->entries, pl->num_entries, dst_index, count);
@@ -258,11 +259,16 @@ static void playlist_transfer_entries_to(struct playlist *pl, int dst_index,
playlist_update_indexes(pl, dst_index + count, -1);
source_pl->num_entries = 0;
+
+ return first ? first->id : 0;
}
// Move all entries from source_pl to pl, appending them after the current entry
// of pl. source_pl will be empty, and all entries have changed ownership to pl.
-void playlist_transfer_entries(struct playlist *pl, struct playlist *source_pl)
+// Return the new ID of the first added entry within pl (0 if source_pl was
+// empty). The IDs of all added entries increase by 1 each entry (you can
+// predict the ID of the last entry).
+int64_t playlist_transfer_entries(struct playlist *pl, struct playlist *source_pl)
{
int add_at = pl->num_entries;
@@ -274,12 +280,12 @@ void playlist_transfer_entries(struct playlist *pl, struct playlist *source_pl)
assert(add_at >= 0);
assert(add_at <= pl->num_entries);
- playlist_transfer_entries_to(pl, add_at, source_pl);
+ return playlist_transfer_entries_to(pl, add_at, source_pl);
}
-void playlist_append_entries(struct playlist *pl, struct playlist *source_pl)
+int64_t playlist_append_entries(struct playlist *pl, struct playlist *source_pl)
{
- playlist_transfer_entries_to(pl, pl->num_entries, source_pl);
+ return playlist_transfer_entries_to(pl, pl->num_entries, source_pl);
}
// Return number of entries between list start and e.