editPlaylist method
- String playlistId, {
- String? title,
- String? description,
- String? privacyStatus,
- bool? collaboration,
- dynamic moveItem,
- String? addPlaylistId,
- PlaylistSortOrder? sortOrder,
- bool? addToTop,
- PlaylistVoteEditOptions? voteOption,
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.collaborationOptional. Enable or disable collaboration. If False and collaboration is not enabled, a Forbidden server error is raised. If True, a newjoinCollaborationTokenis returned. Collaborators cannot interact with private playlists.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.sortOrderOptional. Change the order tracks are returned in. The default isMANUAL.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).voteOption: Optional. Change who can participate in community voting in this playlist. Note that a bad request will be thrown if voteOption is PlaylistVoteEditOptions.COLLABORATORS_ONLY but the playlist is not enabled for collaboration prior to the edit.
Returns Status String, collaboration dict described below, or full response
Dictionary returned when collaboration is true and the request is successful
{ "status": "STATUS_SUCCEEDED", "joinCollaborationToken": "kM9wXdRj2p8v_qL3sHBkTz" }
Implementation
Future<dynamic> editPlaylist(
String playlistId, {
String? title,
String? description,
String? privacyStatus,
bool? collaboration,
dynamic moveItem,
String? addPlaylistId,
PlaylistSortOrder? sortOrder,
bool? addToTop,
PlaylistVoteEditOptions? voteOption,
}) 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 (collaboration != null) {
actions.add({'action': 'ACTION_CREATE_COLLABORATION_INVITE_LINK'});
} else if (!collaboration!) {
actions.add({
'action': 'ACTION_SET_CLOSED_TO_CONTRIBUTIONS',
'closedToContributions': true,
});
}
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 (sortOrder != null) {
actions.add({
'action': 'ACTION_SET_PLAYLIST_VIDEO_ORDER',
'playlistVideoOrder': sortOrder.value,
});
}
if (addToTop != null) {
actions.add({
'action': 'ACTION_SET_ADD_TO_TOP',
'addToTop': addToTop.toString().toLowerCase(),
});
}
if (voteOption != null) {
actions.add({
'action': 'ACTION_SET_ALLOW_ITEM_VOTE',
'itemVotePermission': voteOption.getArgumentForRequest(),
});
}
body['actions'] = actions;
const endpoint = 'browse/edit_playlist';
final response = await sendRequest(endpoint, body);
if (collaboration && response['status'] == ResponseStatus.SUCCEEDED) {
final inviteLink = nav(response, ['collaborationInviteLink']);
return {
'status': response['status'],
'joinCollaborationToken': nav(
Uri.splitQueryString(Uri.parse(inviteLink as String).query),
['jct', 0],
),
};
}
return response.containsKey('status')
? response['status'] as String
: response;
}