editPlaylist method
Edit title, description or privacyStatus of a playlist.
You may also move an item within a playlist or append another playlist to this playlist.
playlistIdPlaylist id.titleOptional. New title for the playlist.descriptionOptional. New description for the playlist.privacyStatusOptional. New privacy status for the playlist.moveItemOptional. Move one item before another. Items are specified by setVideoId, which is the unique id of this playlist item. See getPlaylist.addPlaylistIdOptional. Id of another playlist to add to this playlist.addToTopOptional. Change the state of this playlist to add items to the top of the playlist (iftrue) or the bottom of the playlist (iffalse- 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;
}