Created
September 7, 2013 04:35
-
-
Save ivan3bx/6472831 to your computer and use it in GitHub Desktop.
just mucking around with iTunes XML data..
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
- (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