Permalink
Browse files

initial commit of iTunes module source

  • Loading branch information...
0 parents commit 845f93f8ac4f3645414675df9086a84c943e2813 @skurfer skurfer committed Oct 22, 2011
Showing 313 changed files with 1,924,245 additions and 0 deletions.
@@ -0,0 +1,18 @@
+.svn
+.DS_Store
+._.*
+*.o
+build
+Makefile
+autom4te.cache
+*~
+*.pbxuser
+*.perspectivev3
+*.mode1v3
+*.mode2v3
+*.pbxuser
+*.tm_build_errors
+*.tmproj
+Developer.xcconfig
+*.xcworkspace
+*.xcuserdatad
@@ -0,0 +1,14 @@
+/*
+ * untitled.h
+ * Quicksilver
+ *
+ * Created by Nicholas Jitkoff on 7/3/04.
+ * Copyright 2004 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+
+NSImage * imageForSofaTrack(NSString *artist,NSString *album);
+NSImage *imageForSynergyTrack(NSString *artist,NSString *album,NSString *name);
+NSImage *imageForClutterTrack(NSString *artist,NSString *album);
+NSImage *imageForCommonTrack(NSString *artist,NSString *album,NSNumber *compilation);
@@ -0,0 +1,13 @@
+/*
+ * untitled.c
+ * Quicksilver
+ *
+ * Created by Nicholas Jitkoff on 7/3/04.
+ * Copyright 2004 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#import "QSAlbumArtSources.h"
+
+#import <QSCore/NSString_BLTRExtensions.h>
+
@@ -0,0 +1,20 @@
+//
+// QSiTunesActionProvider.h
+// iTunesPlugIn
+//
+// Created by Nicholas Jitkoff on 1/22/05.
+// Copyright 2005 __MyCompanyName__. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+
+@interface QSiTunesActionProvider : QSActionProvider{
+ NSAppleScript *iTunesScript;
+}
+- (NSAppleScript *)iTunesScript;
+- (QSObject *) playPlaylist:(QSObject *)dObject;
+- (QSObject *) playBrowser:(QSObject *)dObject party:(BOOL)party append:(BOOL)append next:(BOOL)next;
+- (QSObject *) playTrack:(QSObject *)dObject party:(BOOL)party append:(BOOL)append next:(BOOL)next;
+@end
@@ -0,0 +1,205 @@
+//
+// QSiTunesActionProvider.m
+// iTunesPlugIn
+//
+// Created by Nicholas Jitkoff on 1/22/05.
+// Copyright 2005 __MyCompanyName__. All rights reserved.
+//
+
+#import "QSiTunesActionProvider.h"
+
+#import "QSiTunesDefines.h"
+//#import <QSCore/QSMacros.h>
+
+
+#define kQSiTunesPlayItemAction @"QSiTunesPlayItemAction"
+//#define kQSiTunesAppendItemAction @"QSiTunesAppendItemAction"
+
+
+#define kQSiTunesPSPlayAction @"QSiTunesPSPlayAction"
+#define kQSiTunesPSPlayNextAction @"QSiTunesPSPlayNextAction"
+#define kQSiTunesPSAddAction @"QSiTunesPSAddAction"
+
+@implementation QSiTunesActionProvider
+- (id)init {
+ if (self = [super init]) {
+ iTunesScript = nil;
+ }
+ return self;
+}
+
+
+- (NSArray *)validActionsForDirectObject:(QSObject *)dObject indirectObject:(QSObject *)iObject {
+ if ([dObject objectForType:QSiTunesPlaylistIDPboardType]) {
+ return [NSArray arrayWithObject:kQSiTunesPlayItemAction];
+ } else if ([dObject objectForType:QSiTunesBrowserPboardType]) {
+ NSDictionary *browseDict = [dObject objectForType:QSiTunesBrowserPboardType];
+ if (![browseDict objectForKey:@"Criteria"])
+ return nil;
+ }
+ return [NSArray arrayWithObjects:kQSiTunesPSPlayNextAction, kQSiTunesPSAddAction, kQSiTunesPSPlayAction, kQSiTunesPlayItemAction, nil];
+}
+
+- (QSObject *)playItem:(QSObject *)dObject {
+ if ([dObject containsType:QSiTunesPlaylistIDPboardType]) {
+ [self playPlaylist:dObject];
+ } else if ([dObject containsType:QSiTunesBrowserPboardType]) {
+ [self playBrowser:dObject party:NO append:NO next:NO];
+ } else if ([dObject containsType:QSiTunesTrackIDPboardType]) {
+ [self playTrack:dObject party:NO append:NO next:NO];
+ }
+ return nil;
+}
+
+
+- (QSObject *)psPlayItem:(QSObject *)dObject {
+ if ([dObject containsType:QSiTunesBrowserPboardType]) [self playBrowser:dObject party:YES append:NO next:NO];
+ if ([dObject containsType:QSiTunesTrackIDPboardType]) [self playTrack:dObject party:YES append:NO next:NO];
+ return nil;
+}
+- (QSObject *)psAppendItem:(QSObject *)dObject {
+ if ([dObject containsType:QSiTunesBrowserPboardType]) [self playBrowser:dObject party:YES append:YES next:NO];
+ if ([dObject containsType:QSiTunesTrackIDPboardType]) [self playTrack:dObject party:YES append:YES next:NO];
+ return nil;
+}
+- (QSObject *)psPlayNextItem:(QSObject *)dObject {
+ if ([dObject containsType:QSiTunesBrowserPboardType]) [self playBrowser:dObject party:YES append:NO next:YES];
+ if ([dObject containsType:QSiTunesTrackIDPboardType]) [self playTrack:dObject party:YES append:NO next:YES];
+ return nil;
+}
+
+/*
+ - (QSObject *)appendItem:(QSObject *)dObject {
+ if ([dObject objectForType:QSiTunesBrowserPboardType])
+ [self playBrowser:dObject append:YES];
+ if ([dObject objectForType:QSiTunesTrackIDPboardType])
+ [self playTrack:dObject append:YES];
+ return nil;
+ }
+ */
+
+- (QSObject *)playBrowser:(QSObject *)dObject party:(BOOL)party append:(BOOL)append next:(BOOL)next {
+
+ NSDictionary *browseDict = [dObject objectForType:QSiTunesBrowserPboardType];
+ NSMutableDictionary *criteriaDict = [[[browseDict objectForKey:@"Criteria"] mutableCopy] autorelease];
+
+ if ([[criteriaDict objectForKey:@"Artist"] isEqualToString:COMPILATION_STRING])
+ [criteriaDict removeObjectForKey:@"Artist"];
+
+ NSMutableArray *criteria = [NSMutableArray arrayWithArray:[criteriaDict objectsForKeys:[NSArray arrayWithObjects:@"Genre", @"Artist", @"Composer", @"Album", nil]
+ notFoundMarker:[NSAppleEventDescriptor descriptorWithTypeCode:'msng']]];
+ NSDictionary *errorDict = nil;
+
+ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"QSiTunesFastBrowserPlay"] && [browseDict objectForKey:@"Type"])
+ [criteria addObject:[browseDict objectForKey:@"Type"]];
+ else
+ [criteria addObject:[NSAppleEventDescriptor descriptorWithTypeCode:'msng']];
+
+
+ if (party) {
+ if (next) {
+ [[self iTunesScript] executeSubroutine:@"ps_play_next_criteria" arguments:criteria error:&errorDict];
+ } else if (append) {
+ [[self iTunesScript] executeSubroutine:@"ps_add_criteria" arguments:criteria error:&errorDict];
+ } else {
+ [[self iTunesScript] executeSubroutine:@"ps_play_criteria" arguments:criteria error:&errorDict];
+ }
+ } else {
+ [[self iTunesScript] executeSubroutine:(append?@"append_with_criteria":@"play_with_criteria") arguments:criteria error:&errorDict];
+ }
+
+
+ if (errorDict) {NSLog(@"Error: %@", errorDict);}
+ return nil;
+}
+
+- (QSObject *)playTrack:(QSObject *)dObject party:(BOOL)party append:(BOOL)append next:(BOOL)next {
+ //NSArray *trackIDs = [[dObject arrayForType:QSiTunesTrackIDPboardType] valueForKey:@"Track ID"];
+ NSArray *paths = [dObject validPaths];
+
+ if (!paths) return;
+
+ //return;
+ NSDictionary *errorDict = nil;
+
+ // [NSAppleEventDescriptor aliasDescriptorWithFile:[paths objectAtIndex:
+ if (party) {
+ if (next) {
+ //ps_play_next_track can handle a list
+ [[self iTunesScript] executeSubroutine:@"ps_play_next_track"
+ arguments:[NSArray arrayWithObject:[NSAppleEventDescriptor aliasListDescriptorWithArray:paths]]
+ error:&errorDict];
+
+ } else if (append) {
+ [[self iTunesScript] executeSubroutine:@"ps_add_track"
+ arguments:[NSArray arrayWithObject:[NSAppleEventDescriptor aliasListDescriptorWithArray:paths]]
+ error:&errorDict];
+
+ } else {
+ // Play first track, queue rest
+ [[self iTunesScript] executeSubroutine:@"ps_play_track"
+ arguments:[NSArray arrayWithObject:[NSAppleEventDescriptor aliasListDescriptorWithArray:paths]]
+ error:&errorDict];
+
+ // if (count > 1) {
+ // //ps_play_next_track can handle a list
+ // [[self iTunesScript] executeSubroutine:@"ps_play_next_track"
+ // arguments:[NSArray arrayWithObject:[NSAppleEventDescriptor aliasListDescriptorWithArray:[paths subarrayWithRange:NSMakeRange(1, count-1)]]]
+ // error:&errorDict];
+ // }
+ }
+ } else if (append) {
+ [[self iTunesScript] executeSubroutine:@"append_track"
+ arguments:[NSArray arrayWithObject:[NSAppleEventDescriptor aliasDescriptorWithFile:[paths lastObject]]]
+ error:&errorDict];
+
+ } else {
+ NSString *playlist = [dObject objectForMeta:@"QSiTunesSourcePlaylist"];
+ if (playlist) {
+ [[self iTunesScript] executeSubroutine:@"play_track_in_playlist"
+ arguments:[NSArray arrayWithObjects:
+ [NSAppleEventDescriptor aliasListDescriptorWithArray:paths] ,
+ playlist, nil]
+ error:&errorDict];
+
+ } else {
+
+ [[self iTunesScript] executeSubroutine:@"play_track"
+ arguments:[NSArray arrayWithObject:[NSAppleEventDescriptor aliasDescriptorWithFile:[paths lastObject]]]
+ error:&errorDict];
+
+ }
+ }
+ if (errorDict) {NSLog(@"Error: %@", errorDict);}
+ return nil;
+}
+- (QSObject *)playPlaylist:(QSObject *)dObject {
+ NSDictionary *errorDict = nil;
+
+ NSNumber *playlistID = [NSNumber numberWithInt:[[dObject objectForType:QSiTunesPlaylistIDPboardType] intValue]];
+ // if (VERBOSE) NSLog(@"playPlaylist %@", playlistID);
+
+ [[self iTunesScript] executeSubroutine:@"play_playlist" arguments:[NSArray arrayWithObject:playlistID] error:&errorDict];
+ if (errorDict) {
+ NSLog(@"Error: %@", errorDict);
+ } else {
+ return nil;
+ }
+ NSString *playlistName = [[dObject objectForType:QSiTunesPlaylistIDPboardType] objectForKey:@"Name"];
+ if (playlistName) [[self iTunesScript] executeSubroutine:@"play_playlist_name" arguments:[NSArray arrayWithObject:playlistName] error:&errorDict];
+ if (errorDict) {
+ NSLog(@"Error: %@", errorDict);
+ }
+ return nil;
+}
+
+- (NSAppleScript *)iTunesScript {
+ if (!iTunesScript)
+ iTunesScript = [[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:
+ [[NSBundle bundleForClass:[QSiTunesActionProvider class]] pathForResource:@"iTunes" ofType:@"scpt"]] error:nil];
+ return iTunesScript;
+}
+
+
+
+@end
@@ -0,0 +1,17 @@
+//
+// QSiTunesBridge.h
+// iTunesPlugIn
+//
+// Created by Nicholas Jitkoff on 1/22/05.
+// Copyright 2005 __MyCompanyName__. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+extern NSAppleScript *gQSiTunesScript;
+
+NSAppleScript *QSiTunesScript();
+
+
+long QSiTunesCurrentTrackID();
+NSDictionary *QSiTunesFetchInfoForID(NSNumber *theID);
@@ -0,0 +1,80 @@
+//
+// QSiTunesBridge.m
+// iTunesPlugIn
+//
+// Created by Nicholas Jitkoff on 1/22/05.
+// Copyright 2005 __MyCompanyName__. All rights reserved.
+//
+
+#import "QSiTunesBridge.h"
+//#import <QSFoundation/NSAppleScript_BLTRExtensions.h>
+
+
+NSAppleScript *gQSiTunesScript = nil;
+
+NSAppleScript *QSiTunesScript() {
+ if (!gQSiTunesScript) {
+ gQSiTunesScript = [[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:
+ [[NSBundle bundleForClass:NSClassFromString(@"QSiTunesObjectSource")] pathForResource:@"iTunes" ofType:@"scpt"]] error:nil];
+
+ }
+ return gQSiTunesScript;
+}
+
+
+long QSiTunesCurrentTrackID() {
+ static AppleEvent trackEvent = {typeNull, 0} ;
+ if (trackEvent.descriptorType == typeNull) {
+ OSType adrITunes = 'hook';
+ AEBuildAppleEvent ('core', 'getd', typeApplSignature, &adrITunes, sizeof(adrITunes) , kAutoGenerateReturnID, kAnyTransactionID, &trackEvent, NULL,
+ "'----':'obj ' {form:'prop', want:type('prop') , seld:type('pDID'), from:'obj ' {form:'prop', want:type('prop'), seld:type('pTrk'), from:'null'() } } ");
+ }
+ unsigned long trackID = 0;
+ AppleEvent reply;
+ // Send Track ID Event
+ OSStatus err = AESend(&trackEvent, &reply, kAEWaitReply, kAENormalPriority, kNoTimeOut, NULL, NULL);
+ if (err) return 0;
+ AEGetParamPtr(&reply, keyDirectObject, typeLongInteger, NULL, &trackID, sizeof(trackID) , NULL);
+ AEDisposeDesc(&reply);
+ return trackID;
+}
+
+NSDictionary *QSiTunesFetchInfoForID(NSNumber *theID) {
+NSLog(@"Fetch Info For %@", theID);
+ NSDictionary *error = nil;
+ NSAppleEventDescriptor *info = [QSiTunesScript() executeSubroutine:@"extract_track_data" arguments:theID error:&error];
+
+
+ if (error) return nil;
+
+ NSDictionary *dict = [info objectValue];
+
+ //NSLog(@"Fetch Info For %@", [dict description]);
+ NSString *name = [dict objectForKey:[NSNumber numberWithUnsignedLong:'pnam']];
+ NSString *artist = [dict objectForKey:[NSNumber numberWithUnsignedLong:'pArt']];
+ NSString *album = [dict objectForKey:[NSNumber numberWithUnsignedLong:'pAlb']];
+ NSString *location = [dict objectForKey:[NSNumber numberWithUnsignedLong:'pLoc']];
+ NSString *kind = [dict objectForKey:[NSNumber numberWithUnsignedLong:'pKnd']];
+ NSNumber *rating = [dict objectForKey:[NSNumber numberWithUnsignedLong:'pRte']];
+
+ if ([location isKindOfClass:[NSURL class]]) location = [(NSURL *)location absoluteString];
+
+ //NSLog(@"loc %@ %d", location, 'msng');
+ if ([location isKindOfClass:[NSAppleEventDescriptor class]]) location = nil;
+ if ([album isKindOfClass:[NSAppleEventDescriptor class]]) album = nil;
+ if ([artist isKindOfClass:[NSAppleEventDescriptor class]]) artist = nil;
+ if ([kind isKindOfClass:[NSAppleEventDescriptor class]]) kind = nil;
+ if ([rating isKindOfClass:[NSAppleEventDescriptor class]]) rating = nil;
+ //if ([location isKindOfClass:[NSArray class]]) location = [location lastObject];
+
+ NSMutableDictionary *trackInfo = [NSMutableDictionary dictionary];
+ if (name) [trackInfo setObject:name forKey:@"Name"];
+ if (location) [trackInfo setObject:location forKey:@"Location"];
+ if (album) [trackInfo setObject:album forKey:@"Album"];
+ if (artist) [trackInfo setObject:artist forKey:@"Artist"];
+ if (rating) [trackInfo setObject:rating forKey:@"Rating"];
+ if (kind) [trackInfo setObject:kind forKey:@"Kind"];
+ [trackInfo setObject:[NSNumber numberWithInt:1] forKey:@"Artwork Count"];
+ //if (fDEV) NSLog(@"info %@", trackInfo);
+ return trackInfo;
+}
Oops, something went wrong.

0 comments on commit 845f93f

Please sign in to comment.