Browse files

Merge branch 'command_line_opts'

  • Loading branch information...
2 parents 778d856 + c0f746f commit 3a934bb3152df436078d70c1fa110bc3b0e23d67 @tonywok tonywok committed Apr 25, 2012
View
1 .gitignore
@@ -1,6 +1,7 @@
# App
app_key.c
spotify_appkey.c
+spotify_appkey.key
config.h
# Xcode
View
2 cocoa_spotify.xcodeproj/xcuserdata/tonywok.xcuserdatad/xcschemes/CoccoaSpotbox.xcscheme
@@ -41,7 +41,7 @@
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
- selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
View
5 cocoa_spotify.xcodeproj/xcuserdata/tonywok.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -9,6 +9,11 @@
<key>orderHint</key>
<integer>0</integer>
</dict>
+ <key>cocoa_spotify.xcscheme</key>
+ <dict>
+ <key>orderHint</key>
+ <integer>1</integer>
+ </dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
View
88 cocoa_spotify/main.m
@@ -12,49 +12,63 @@
#import "SpotboxPlayer.h"
#import "SpotboxPlaylist.h"
#import "ZmqDispatch.h"
-#import "config.h"
-#include "spotify_appkey.c"
int main (int argc, const char * argv[]) {
@autoreleasepool {
- // Initialize and fiddle with Spotify Session
- [SPSession initializeSharedSessionWithApplicationKey:[NSData dataWithBytes:&g_spotify_appkey length:g_spotify_appkey_size]
- userAgent:@"com.edgecase.spotbox"
- error:nil];
- // ZMQ Initialization
- ZMQContext *zmq_ctx = [[ZMQContext alloc] initWithIOThreads:1];
- NSString *pub_port = @"tcp://127.0.0.1:12001";
- NSString *sub_port = @"tcp://127.0.0.1:12000";
- ZmqDispatch *dispatcher = [[ZmqDispatch alloc] initWithContext:zmq_ctx publishTo:pub_port subscribeTo:sub_port];
-
- // Initialize spotbox classes
- SpotboxPlaylist *playlistManager = [[SpotboxPlaylist alloc] initWithDispatcher:dispatcher];
- SpotboxPlayer *playerManager = [[SpotboxPlayer alloc] initWithDispatcher:dispatcher];
+ NSArray *args = [[NSProcessInfo processInfo] arguments];
- [[SPSession sharedSession] setDelegate:playerManager];
-
- NSFileManager *fm = [NSFileManager defaultManager];
- NSString *username = [fm stringWithFileSystemRepresentation:SPOTIFY_USERNAME length:10];
- NSString *password = [fm stringWithFileSystemRepresentation:SPOTIFY_PASSWORD length:10];
- [[SPSession sharedSession] attemptLoginWithUserName:username
- password:password
- rememberCredentials:NO];
+ if ([args count] == 3) {
+ NSLog(@"Error: Please supply the location of the file containing your appkey");
+ NSLog(@"");
+ NSLog(@"usage: cocoa_spotify ~/location/of/appkey.key username password");
+ exit(1);
+ } else {
+ NSString *appkeyLocation = [args objectAtIndex:1];
+ NSFileManager *filemgr = [NSFileManager defaultManager];
+ NSString *path = [appkeyLocation stringByExpandingTildeInPath];
+
+ if ([filemgr fileExistsAtPath:path] == NO) {
+ NSLog(@"Error: Unable to locate file at: %@", appkeyLocation);
+ exit(1);
+ } else {
+ NSData *key = [NSData dataWithContentsOfFile:path];
+ NSError *error = nil;
- // create a timer for run loop
- NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.2
- target:dispatcher
- selector:@selector(receiveData:)
- userInfo:nil
- repeats:YES];
- // Run Loop
- NSRunLoop *run_loop = [NSRunLoop currentRunLoop];
- [run_loop addTimer:timer forMode:NSDefaultRunLoopMode];
- [run_loop run];
-
- // Close sockets later
- [[zmq_ctx sockets] makeObjectsPerformSelector:@selector(close)];
- return EXIT_SUCCESS;
+ [SPSession initializeSharedSessionWithApplicationKey:[NSData dataWithData:key] userAgent:@"com.edgecase.spotbox" error:&error];
+ if (error != nil) { NSLog(@"error while creating session: %@", error); }
+
+ // ZMQ Initialization
+ ZMQContext *zmq_ctx = [[ZMQContext alloc] initWithIOThreads:1];
+ NSString *pub_port = @"tcp://127.0.0.1:12001";
+ NSString *sub_port = @"tcp://127.0.0.1:12000";
+ ZmqDispatch *dispatcher = [[ZmqDispatch alloc] initWithContext:zmq_ctx publishTo:pub_port subscribeTo:sub_port];
+
+ // Initialize spotbox classes
+ SpotboxPlaylist *playlistManager = [[SpotboxPlaylist alloc] initWithDispatcher:dispatcher];
+ SpotboxPlayer *playerManager = [[SpotboxPlayer alloc] initWithDispatcher:dispatcher];
+
+ [[SPSession sharedSession] setDelegate:playerManager];
+ [[SPSession sharedSession] attemptLoginWithUserName:[args objectAtIndex:2]
+ password:[args objectAtIndex:3]
+ rememberCredentials:NO];
+
+ // create a timer for run loop
+ NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.2
+ target:dispatcher
+ selector:@selector(receiveData:)
+ userInfo:nil
+ repeats:YES];
+ // Run Loop
+ NSRunLoop *run_loop = [NSRunLoop currentRunLoop];
+ [run_loop addTimer:timer forMode:NSDefaultRunLoopMode];
+ [run_loop run];
+
+ // Close sockets later
+ [[zmq_ctx sockets] makeObjectsPerformSelector:@selector(close)];
+ return EXIT_SUCCESS;
+ }
+ }
}
}

0 comments on commit 3a934bb

Please sign in to comment.