Created
September 7, 2013 18:40
-
-
Save ivan3bx/6478071 to your computer and use it in GitHub Desktop.
Example of the ITLibrary API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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