removePlaylistItems method
Remove songs from an existing playlist.
playlistId
Playlist id.videos
List of PlaylistItems, see getPlaylist. Must containvideoId
andsetVideoId
.
Returns status String or full response.
Implementation
Future<dynamic> removePlaylistItems(
String playlistId,
List<JsonMap> videos,
) async {
checkAuth();
final filtered =
videos
.where(
(v) => v.containsKey('videoId') && v.containsKey('setVideoId'),
)
.toList();
if (filtered.isEmpty) {
throw YTMusicUserError(
'Cannot remove songs, because setVideoId is missing. Do you own this playlist?',
);
}
final body = {'playlistId': validatePlaylistId(playlistId), 'actions': []};
for (final video in filtered) {
(body['actions']! as List).add({
'setVideoId': video['setVideoId'],
'removedVideoId': video['videoId'],
'action': 'ACTION_REMOVE_VIDEO',
});
}
const endpoint = 'browse/edit_playlist';
final response = await sendRequest(endpoint, body);
return response.containsKey('status') ? response['status'] : response;
}