Skip to content

Instantly share code, notes, and snippets.

@sommestad
Created February 25, 2012 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sommestad/1909096 to your computer and use it in GitHub Desktop.
Save sommestad/1909096 to your computer and use it in GitHub Desktop.
Moving a playlist to a folder.
if (_appFolder) {
NSArray * containerPlaylists = container.playlists;
for (SPPlaylist * containerPlaylist in containerPlaylists) {
// move all playlists tagged with SpotON Radio:
if ([containerPlaylist.name rangeOfString: kPlaylistNameMatch].location != NSNotFound) {
NSInteger playlistIndex = [[container playlists] indexOfObject: containerPlaylist];
DLog(@"-> MOVE playlist %@ at index %i", containerPlaylist.name, playlistIndex);
// retain playlist while working with it
[containerPlaylist retain];
// move playlist
NSError * error = nil;
BOOL success = [container movePlaylistOrFolderAtIndex:playlistIndex ofParent: nil toIndex: 0 ofNewParent: _appFolder error: &error];
if (success) {
// rename playlist
DLog(@"Success! Playlist moved to folder (error: %@).", error);
// check the folder structure
for (SPPlaylist * folderPlaylist in [_appFolder playlists]) {
DLog(@"Playlist %@ in folder...", folderPlaylist.name);
}
} else {
DLog(@"Failed to move playlist %@ with error: %@", containerPlaylist.name, error);
}
// release playlist
[containerPlaylist release];
}
}
}
@sommestad
Copy link
Author

_appFolder is a previously stored instance var, representing the folder to which I want to move the playlist.

When I'm running this code, I'm getting the "success" message, the folder and playlist is created in Spotify (with an added track), but the playlist hasn't been moved to the folder.

@sommestad
Copy link
Author

The log output on #23-#25 doesn't print out anything and the structure doesn't look right in Spotify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment