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