Permalink
Browse files

[Lastfm scrobblePointForTrackWithDurationInSeconds]

  • Loading branch information...
mxcl committed Jun 26, 2010
1 parent b130dfe commit d7136dcb87fd1d1d71071da5ad89d36e293bf500
Showing with 11 additions and 9 deletions.
  1. +1 −9 ITunesListener.m
  2. +2 −0 lastfm.h
  3. +8 −0 lastfm.m
View
@@ -33,13 +33,6 @@ static time_t now()
return t;
}
-static uint scrobble_time(uint duration)
-{
- if (duration > 240*2) return 240;
- if (duration < 30*2) return 30;
- return duration/2;
-}
-
@implementation ITunesListener
@@ -144,10 +137,9 @@ -(void)submit
if (state == STATE_PAUSED)
pause_time = time - pause_time;
- uint const duration = [[track objectForKey:@"Total Time"] longLongValue] / 1000;
uint const playtime = time - (start_time + pause_time);
// we take off three seconds because durations often have a small error
- uint const scrobtime = scrobble_time(duration) - 3;
+ uint const scrobtime = [Lastfm scrobblePointForTrackWithDurationInSeconds:track.duration];
if (playtime >= scrobtime)
[lastfm scrobble:track startTime:start_time];
View
@@ -50,4 +50,6 @@
-(void)updateNowPlaying:(NSDictionary*)track;
-(void)scrobble:(NSDictionary*)track startTime:(time_t)start_time;
++(unsigned)scrobblePointForTrackWithDurationInSeconds:(unsigned)duration;
+
@end
View
@@ -125,6 +125,14 @@ +(NSURL*)urlForUser:(NSString*)username
}
++(unsigned)scrobblePointForTrackWithDurationInSeconds:(unsigned)duration
+{
+ if (duration > 240*2) return 240;
+ if (duration < 30*2) return 30;
+ return duration/2;
+}
+
+
#pragma mark HTTP
-(NSXMLDocument*)get:(NSMutableDictionary*)params to:(NSString*)method

0 comments on commit d7136dc

Please sign in to comment.