removePlaylistItems method

Future removePlaylistItems(
  1. String playlistId,
  2. List<JsonMap> videos
)

Remove songs from an existing playlist.

  • playlistId Playlist id.
  • videos List of PlaylistItems, see getPlaylist. Must contain videoId and setVideoId.

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;
}