diff options
author | wm4 <wm4@nowhere> | 2020-03-27 00:57:11 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-03-27 00:57:11 +0100 |
commit | df0d8cda08463b291203812ec475ca185bc8e947 (patch) | |
tree | bd10780993e10b5fbc089f1b9bb2019a830d4a3f /common | |
parent | d3be6a61634ff6f9ba217320eaa9fb9349a5c144 (diff) | |
download | mpv-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')
-rw-r--r-- | common/playlist.c | 18 | ||||
-rw-r--r-- | common/playlist.h | 4 |
2 files changed, 14 insertions, 8 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. diff --git a/common/playlist.h b/common/playlist.h index f8dfbb2ba2..5f84e3b413 100644 --- a/common/playlist.h +++ b/common/playlist.h @@ -103,8 +103,8 @@ struct playlist_entry *playlist_entry_get_rel(struct playlist_entry *e, void playlist_add_base_path(struct playlist *pl, bstr base_path); void playlist_add_redirect(struct playlist *pl, const char *redirected_from); void playlist_set_stream_flags(struct playlist *pl, int flags); -void playlist_transfer_entries(struct playlist *pl, struct playlist *source_pl); -void playlist_append_entries(struct playlist *pl, struct playlist *source_pl); +int64_t playlist_transfer_entries(struct playlist *pl, struct playlist *source_pl); +int64_t playlist_append_entries(struct playlist *pl, struct playlist *source_pl); int playlist_entry_to_index(struct playlist *pl, struct playlist_entry *e); int playlist_entry_count(struct playlist *pl); |