X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/6162e11fb9ec9ca0f4add4d5838e98a31ead4a21..a5c365dd668dee7c653dbafee270e5e05025a2ab:/iTunesRemote.m?ds=sidebyside diff --git a/iTunesRemote.m b/iTunesRemote.m index 8bc60c0..997922c 100755 --- a/iTunesRemote.m +++ b/iTunesRemote.m @@ -175,7 +175,7 @@ } for (k = 1; k <= numSources ; k++) { - const signed long numPlaylists = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:[NSString stringWithFormat:@"kocl:type('cPly'), '----':obj { form:'indx', want:type('cSrc'), seld:long(%u), from:() }",k] eventClass:@"core" eventID:@"cnte" appPSN:savedPSN]; + const signed long numPlaylists = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:[NSString stringWithFormat:@"kocl:type('cPly'), '----':obj { form:'indx', want:type('cSrc'), seld:long(%u), from:() }",k] eventClass:@"core" eventID:@"cnte" appPSN:savedPSN];; unsigned long fourcc = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:[NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pKnd'), from:obj { form:'indx', want:type('cSrc'), seld:long(%u), from:() } }",k] eventClass:@"core" eventID:@"getd" appPSN:savedPSN]; NSString *sourceName = [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pnam'), from:obj { form:'indx', want:type('cSrc'), seld:long(%u), from:() } }",k] eventClass:@"core" eventID:@"getd" appPSN:savedPSN]; unsigned long index = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:[NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pidx'), from:obj { form:'indx', want:type('cSrc'), seld:long(%u), from:() } }",k] eventClass:@"core" eventID:@"getd" appPSN:savedPSN]; @@ -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; @@ -342,7 +378,12 @@ { NSString *temp1; ITDebugLog(@"Getting current unique identifier."); - temp1 = [NSString stringWithFormat:@"%i-%i", [self currentPlaylistIndex], [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pDID" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN]]; + int cls = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pcls" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN]; + if ( ([self currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist) || (cls == 'cURT') ) { + temp1 = [[ITAppleEventCenter sharedCenter] sendAEWithRequestedKey:@"pStT" eventClass:@"core" eventID:@"getd" appPSN:savedPSN]; + } else { + temp1 = [NSString stringWithFormat:@"%i-%i", [self currentPlaylistIndex], [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pDID" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN]]; + } ITDebugLog(@"Getting current unique identifier done."); return ( ([temp1 length]) ? temp1 : nil ) ; } @@ -729,6 +770,38 @@ 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); + + //Delete old MenuTunes playlist + ITSendAEWithString(@"'----':obj { form:'name', want:type('cPly'), seld:\"MenuTunes\", from:'null'() }", 'core', 'delo', &savedPSN); + + //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];