//Create and send the request
NSMutableURLRequest *request = [[NSURLRequest requestWithURL:_postURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:15] mutableCopy];
- NSLog(@"Posting Audioscrobbler URL request: %@", requestString);
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[requestString dataUsingEncoding:NSUTF8StringEncoding]];
_currentStatus = AudioscrobblerSubmittingTracksStatus;
responseAction = [lines objectAtIndex:0];
}
ITDebugLog(@"Audioscrobbler: Response %@", string);
- NSLog(@"Audioscrobbler: Response %@", string);
if (_currentStatus == AudioscrobblerRequestingHandshakeStatus) {
if ([lines count] < 2) {
//We have a protocol error
//Bad auth
} else if (([responseAction length] > 5) && [[responseAction substringToIndex:5] isEqualToString:@"FAILED"]) {
ITDebugLog(@"Audioscrobbler: Submission failed (%@)", [responseAction substringFromIndex:6]);
- NSLog(@"Audioscrobbler: Submission failed (%@)", [responseAction substringFromIndex:6]);
key = @"audioscrobbler_submission_failed";
comment = @"Last track submission failed - see console for error";
//Failed
int elapsed = [[self currentRemote] currentSongPlayed], length = [[self currentRemote] currentSongDuration], requiredInterval = ((length / 2 < 240) ? length / 2 : 240);
if ((abs(elapsed - requiredInterval) < 5) && ([[self currentRemote] playerPlayingState] == ITMTRemotePlayerPlaying)) {
NSString *title = [[self currentRemote] currentSongTitle], *artist = [[self currentRemote] currentSongArtist];
- NSLog(@"Audioscrobbler: Submitting");
if (title && artist) {
ITDebugLog(@"Audioscrobbler: Submitting current track");
[[AudioscrobblerController sharedController] submitTrack:title
} else if (requiredInterval - elapsed > 0) {
_audioscrobblerInterval = requiredInterval - elapsed;
[_audioscrobblerTimer release];
- NSLog(@"Audioscrobbler: Creating a new timer that will run in %i seconds", _audioscrobblerInterval);
ITDebugLog(@"Audioscrobbler: Creating a new timer that will run in %i seconds", _audioscrobblerInterval);
_audioscrobblerTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:_audioscrobblerInterval] interval:1.0 target:self selector:@selector(submitAudioscrobblerTrack:) userInfo:nil repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:_audioscrobblerTimer forMode:NSDefaultRunLoopMode];
- } else {
- NSLog(@"Audioscrobbler: Skipping submission. %i, %i", requiredInterval, elapsed);
}
NS_HANDLER
[self networkError:localException];
if (status != noErr) {
ITDebugLog(@"Audioscrobbler: Error getting keychain item password: %i", status);
} else {
- NSLog(@"Audioscrobbler: password buffer: \"%s\" \"Length: %i\"", buffer, length);
pass = [[NSString alloc] initWithBytes:buffer length:length encoding:NSUTF8StringEncoding];
}
if (status != noErr) {
SecKeychainItemFreeContent(NULL, buffer);
CFRelease(item);
}
- NSLog(@"Audioscrobbler: Retrieved password: \"%@\"", pass);
return [pass autorelease];
}