editPlaylist method

Future editPlaylist(
  1. String playlistId, {
  2. String? title,
  3. String? description,
  4. String? privacyStatus,
  5. dynamic moveItem,
  6. String? addPlaylistId,
  7. bool? addToTop,
})

Edit title, description or privacyStatus of a playlist.

You may also move an item within a playlist or append another playlist to this playlist.

  • playlistId Playlist id.
  • title Optional. New title for the playlist.
  • description Optional. New description for the playlist.
  • privacyStatus Optional. New privacy status for the playlist.
  • moveItem Optional. Move one item before another. Items are specified by setVideoId, which is the unique id of this playlist item. See getPlaylist.
  • addPlaylistId Optional. Id of another playlist to add to this playlist.
  • addToTop Optional. Change the state of this playlist to add items to the top of the playlist (if true) or the bottom of the playlist (if false - this is also the default of a new playlist).

Returns status String or full response.

Implementation

Future<dynamic> editPlaylist(
  String playlistId, {
  String? title,
  String? description,
  String? privacyStatus,
  dynamic moveItem,
  String? addPlaylistId,
  bool? addToTop,
}) async {
  checkAuth();
  final body = <String, dynamic>{
    'playlistId': validatePlaylistId(playlistId),
  };
  final actions = <JsonMap>[];

  if (title != null) {
    actions.add({
      'action': 'ACTION_SET_PLAYLIST_NAME',
      'playlistName': title,
    });
  }
  if (description != null) {
    actions.add({
      'action': 'ACTION_SET_PLAYLIST_DESCRIPTION',
      'playlistDescription': description,
    });
  }
  if (privacyStatus != null) {
    actions.add({
      'action': 'ACTION_SET_PLAYLIST_PRIVACY',
      'playlistPrivacy': privacyStatus,
    });
  }

  if (moveItem != null) {
    final action = {
      'action': 'ACTION_MOVE_VIDEO_BEFORE',
      'setVideoId':
          moveItem is String ? moveItem : (moveItem as List<String>)[0],
    };
    if (moveItem is List && moveItem.length > 1) {
      action['movedSetVideoIdSuccessor'] = (moveItem as List<String>)[1];
    }
    actions.add(action);
  }

  if (addPlaylistId != null) {
    actions.add({
      'action': 'ACTION_ADD_PLAYLIST',
      'addedFullListId': addPlaylistId,
    });
  }
  if (addToTop != null) {
    actions.add({
      'action': 'ACTION_SET_ADD_TO_TOP',
      'addToTop': addToTop.toString(),
    });
  }

  body['actions'] = actions;
  const endpoint = 'browse/edit_playlist';
  final response = await sendRequest(endpoint, body);
  return response.containsKey('status') ? response['status'] : response;
}