X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/c99066bb8eb3a6f60be746f1ae150390dea4bd51..f75034b0016748a0727852ce6c94c22350bbc101:/iTunesRemote.m diff --git a/iTunesRemote.m b/iTunesRemote.m index dde194f..35c9990 100755 --- a/iTunesRemote.m +++ b/iTunesRemote.m @@ -226,6 +226,42 @@ return [allSources autorelease]; } +- (NSArray *)artists +{ + NSAppleEventDescriptor *rawr = ITSendAEWithString(@"'----':obj { form:'prop', want:type('prop'), seld:type('pArt'), from:obj { form:'indx', want:type('cTrk'), seld:abso($616C6C20$), from:obj { form:'indx', want:type('cPly'), seld:long(1), from:obj { form:'indx', want:type('cSrc'), seld:long(1), from:() } } } }", 'core', 'getd', &savedPSN); + int i; + NSMutableArray *array = [[NSMutableArray alloc] init]; + NSArray *returnArray; + for (i = 1; i <= [rawr numberOfItems]; i++) { + NSString *artist = [[rawr descriptorAtIndex:i] stringValue]; + if (artist && [artist length] && ![array containsObject:artist]) { + [array addObject:artist]; + } + } + [array sortUsingSelector:@selector(caseInsensitiveCompare:)]; + returnArray = [NSArray arrayWithArray:array]; + [array release]; + return returnArray; +} + +- (NSArray *)albums +{ + NSAppleEventDescriptor *rawr = ITSendAEWithString(@"'----':obj { form:'prop', want:type('prop'), seld:type('pAlb'), from:obj { form:'indx', want:type('cTrk'), seld:abso($616C6C20$), from:obj { form:'indx', want:type('cPly'), seld:long(1), from:obj { form:'indx', want:type('cSrc'), seld:long(1), from:() } } } }", 'core', 'getd', &savedPSN); + int i; + NSMutableArray *array = [[NSMutableArray alloc] init]; + NSArray *returnArray; + for (i = 1; i <= [rawr numberOfItems]; i++) { + NSString *album = [[rawr descriptorAtIndex:i] stringValue]; + if (album && [album length] && ![array containsObject:album]) { + [array addObject:album]; + } + } + [array sortUsingSelector:@selector(caseInsensitiveCompare:)]; + returnArray = [NSArray arrayWithArray:array]; + [array release]; + return returnArray; +} + - (int)numberOfSongsInPlaylistAtIndex:(int)index { int temp1; @@ -734,6 +770,44 @@ return YES; } +- (BOOL)makePlaylistWithTerm:(NSString *)term ofType:(int)type +{ + int i; + + //Get fixed indexing status + BOOL fixed = [ITSendAEWithString(@"'----':obj { form:'prop', want:type('prop'), seld:type('pFix'), from:'null'() }", 'core', 'getd', &savedPSN) booleanValue]; + + //Enabled fixed indexing + ITSendAEWithString(@"data:long(1), '----':obj { form:'prop', want:type('prop'), seld:type('pFix'), from:'null'() }", 'core', 'setd', &savedPSN); + + //Search for the term + NSAppleEventDescriptor *searchResults = ITSendAEWithString([NSString stringWithFormat:@"pTrm:\"%@\", pAre:'%@', '----':obj { form:'indx', want:type('cPly'), seld:long(1), from:obj { form:'indx', want:type('cSrc'), seld:long(1), from:'null'() } }", term, ((type == 1) ? @"kSrR" : @"kSrL")], 'hook', 'Srch', &savedPSN); + + //If MenuTunes playlist exists + if ([ITSendAEWithString(@"'----':obj { form:'name', want:type('cPly'), seld:\"MenuTunes\", from:'null'() }", 'core', 'doex', &savedPSN) booleanValue]) { + //Clear old MenuTunes playlist + int numSongs = [ITSendAEWithString(@"kocl:type('cTrk'), '----':obj { form:'name', want:type('cPly'), seld:\"MenuTunes\", from:obj { form:'prop', want:type('prop'), seld:type('ctnr'), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } } }", 'core', 'cnte', &savedPSN) int32Value]; + for (i = 1; i <= numSongs; i++) { + ITSendAEWithString(@"'----':obj { form:'indx', want:type('cTrk'), seld:long(1), from:obj { form:'name', want:type('cPly'), seld:\"MenuTunes\", from:'null'() } }", 'core', 'delo', &savedPSN); + } + } else { + //Create MenuTunes playlist + ITSendAEWithString(@"prdt:{ pnam:\"MenuTunes\" }, kocl:type('cPly'), &subj:()", 'core', 'crel', &savedPSN); + } + + //Duplicate search results to playlist + for (i = 1; i <= [searchResults numberOfItems]; i++) { + ITSendAEWithStringAndObject(@"insh:obj { form:'name', want:type('cPly'), seld:\"MenuTunes\", from:'null'() }", [[searchResults descriptorAtIndex:i] aeDesc], 'core', 'clon', &savedPSN); + } + //Reset fixed indexing + ITSendAEWithString([NSString stringWithFormat:@"data:long(%i), '----':obj { form:'prop', want:type('prop'), seld:type('pFix'), from:'null'() }", fixed], 'core', 'setd', &savedPSN); + + //Play MenuTunes playlist + //ITSendAEWithString(@"'----':obj { form:'name', want:type('cPly'), seld:\"MenuTunes\", from:'null'() }", 'hook', 'Play', &savedPSN); + + return YES; +} + - (ProcessSerialNumber)iTunesPSN { /*NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications];