Skip to content

Instantly share code, notes, and snippets.

@ivan3bx
Created September 7, 2013 18:40
Show Gist options
  • Save ivan3bx/6478071 to your computer and use it in GitHub Desktop.
Save ivan3bx/6478071 to your computer and use it in GitHub Desktop.
Example of the ITLibrary API
NSError *error = nil;
ITLibrary *library = [ITLibrary libraryWithAPIVersion:@"1.0" error:&error];
if (library)
{
NSArray *playlists = library.allPlaylists;
NSArray *tracks = library.allMediaItems;
NSLog(@"Playlists count: %lu", [playlists count]);
NSLog(@"Tracks count: %lu", [tracks count]);
NSMutableSet *albums_artwork = [[NSMutableSet alloc] init];
NSMutableSet *albums_all = [[NSMutableSet alloc] init];
[tracks enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
ITLibMediaItem *item = (ITLibMediaItem *)obj;
if (item.album) {
if (item.hasArtworkAvailable && item.mediaKind == ITLibMediaItemMediaKindSong) {
[albums_artwork addObject:item.album];
}
[albums_all addObject:item.album];
} else {
NSLog(@"No artwork for album: %@", item.album);
}
}];
NSLog(@"Albums with artwork: %lu", [albums_artwork count]);
NSLog(@"Albums total: %lu", [albums_all count]);
} else {
NSLog(@"Error is: %@", [error userInfo]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment