Skip to content

Instantly share code, notes, and snippets.

@ivan3bx
Created September 7, 2013 04:35
Show Gist options
  • Save ivan3bx/6472831 to your computer and use it in GitHub Desktop.
Save ivan3bx/6472831 to your computer and use it in GitHub Desktop.
just mucking around with iTunes XML data..
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSString *path = [NSString stringWithFormat:@"%@/Music/iTunes/iTunes Library.xml", NSHomeDirectory()];
NSData *xmlData;
NSDictionary *plist;
xmlData = [NSData dataWithContentsOfFile:path];
NSString *error;
NSPropertyListFormat format;
plist = (NSDictionary *)[NSPropertyListSerialization propertyListFromData:xmlData
mutabilityOption:NSPropertyListImmutable
format:&format
errorDescription:&error];
if(!plist){
NSLog(@"Error: %@", error);
} else {
// Get tracks
NSDictionary *tracks = [plist objectForKey:@"Tracks"];
NSLog(@"Number of Tracks: %lu", [tracks count]);
// Find all purchased albums!
NSMutableSet *albumNames = [[NSMutableSet alloc] init];
[tracks enumerateKeysAndObjectsWithOptions:NSEnumerationConcurrent
usingBlock: ^(id key, NSDictionary *trackInfo, BOOL *stop) {
if ([@"Purchased AAC audio file" isEqualTo:[trackInfo objectForKey:@"Kind"]]) {
[albumNames addObject:[trackInfo objectForKey:@"Album"]];
}
}];
NSLog(@"Number of Albums: %lu", [albumNames count]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment