Readding LibValidate as binary
[MenuTunes.git] / iTunesRemote.m
index cb976a6..f197b97 100755 (executable)
 {
     long duration;
     long current;
+    long final;
+    NSString *finalString;
     
     ITDebugLog(@"Getting current song remaining time.");
     
                         sendTwoTierAEWithRequestedKeyForNumber:@"pDur" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
     current = [[ITAppleEventCenter sharedCenter]
                         sendAEWithRequestedKeyForNumber:@"pPos" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+                        
+    final = duration - current;
+    finalString = [self formatTimeInSeconds:final];
+    
     ITDebugLog(@"Getting current song remaining time done.");
-    return [[NSNumber numberWithLong:duration - current] stringValue];
+    
+    return finalString;
 }
 
 - (NSString *)currentSongElapsed
 {
-    long current;
+    long final;
+    NSString *finalString;
     
     ITDebugLog(@"Getting current song elapsed time.");
     
-    current = [[ITAppleEventCenter sharedCenter]
+    final = [[ITAppleEventCenter sharedCenter]
                         sendAEWithRequestedKeyForNumber:@"pPos" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+                        
+    finalString = [self formatTimeInSeconds:final];
     ITDebugLog(@"Getting current song elapsed time done.");
-    return [[NSNumber numberWithLong:current] stringValue];
+    return finalString;
 }
 
 - (float)currentSongRating
     } else {
         final = NO;
     }
-    NSLog(@"shuffleEnabled: final = %i", final);
     ITDebugLog(@"Getting shuffle enabled status done.");
     return final;
 }
     return number;
 }
 
+- (NSString*)formatTimeInSeconds:(long)seconds {
+    long final = seconds;
+    NSString *finalString;
+    if (final > 60) {
+        if (final > 3600) {
+            finalString = [NSString stringWithFormat:@"%i:%@:%@",(final / 3600),[self zeroSixty:(int)((final % 3600) / 60)],[self zeroSixty:(int)((final % 3600) % 60)]];
+        } else {
+            finalString = [NSString stringWithFormat:@"%i:%@",(final / 60),[self zeroSixty:(int)(final % 60)]];
+        }
+    } else {
+        finalString = [NSString stringWithFormat:@"0:%@",[self zeroSixty:(int)final]];
+    }
+    return finalString;
+}
+- (NSString*)zeroSixty:(int)seconds {
+    if ( (seconds < 10) && (seconds > 0) ) {
+        return [NSString stringWithFormat:@"0%i",seconds];
+    } else if ( (seconds == 0) ) {
+        return [NSString stringWithFormat:@"00"];
+    } else {
+        return [NSString stringWithFormat:@"%i",seconds];
+    }
+}
+
 @end