Bug fixes.
[clinton/xbmc-groove.git] / resources / lib / GroovesharkAPI.py
index 7790f17..a011276 100644 (file)
@@ -39,16 +39,17 @@ class GrooveAPI:
        _userID = 0
        _lastSessionTime = 0
        _key = md5.new(os.path.basename("GroovesharkAPI.py")).hexdigest()
-       _apiDebug = False
+       _debugging = False
 
        # Constructor
-       def __init__(self):
+       def __init__(self, debug):
                
+               self._debugging = debug
                self.simplejson = simplejson
                self.cacheDir = os.path.join(tempfile.gettempdir(), 'groovesharkapi')
                if os.path.isdir(self.cacheDir) == False:
                        os.makedirs(self.cacheDir)
-                       if self._apiDebug:
+                       if self._debugging:
                                print "Made " + self.cacheDir
                self._getSavedSession()
                # session ids last 2 weeks
@@ -57,7 +58,7 @@ class GrooveAPI:
                        if self._sessionID == '':
                                raise StandardError('Failed to get session id')
                        else:
-                               if self._apiDebug:
+                               if self._debugging:
                                        print "New GrooveAPI session id: " + self._sessionID
                                self._ip = self._getIP()
                                self._country = self._getCountry()
@@ -76,7 +77,7 @@ class GrooveAPI:
                        req = urllib2.Request(url, postData)
                        response = urllib2.urlopen(req)
                        result = response.read()
-                       if self._apiDebug:
+                       if self._debugging:
                                print "Response..."
                                pprint.pprint(result)
                        response.close()
@@ -104,7 +105,7 @@ class GrooveAPI:
                req = urllib2.Request(url)
                response = urllib2.urlopen(req)
                result = response.read()
-               if self._apiDebug:
+               if self._debugging:
                        print "Request..."
                        pprint.pprint(result)
                response.close()
@@ -162,7 +163,7 @@ class GrooveAPI:
                try:
                        myip = urllib2.urlopen('http://whatismyip.org').read()
                        if re.match("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$", myip):
-                               if self._apiDebug:
+                               if self._debugging:
                                        print "IP is " + myip
                                return myip
                except:
@@ -426,23 +427,14 @@ class GrooveAPI:
                        return False
                
        # After 30s play time
-       def markStreamKeyOver30Secs(self, lastStreamKey, lastStreamServerID):
-               params = { "streamKey" : lastStreamKey, "streamServerID" : lastStreamServerID }
+       def markStreamKeyOver30Secs(self, streamKey, streamServerID):
+               params = { "streamKey" : streamKey, "streamServerID" : streamServerID }
                self._callRemote("markStreamKeyOver30Secs", params)
 
        # Song complete
-       def markSongComplete(self, songid, lastStreamKey, lastStreamServerID):          
-               params = { "songID" : songid, "streamKey" : lastStreamKey, "streamServerID" : lastStreamServerID }
+       def markSongComplete(self, songid, streamKey, streamServerID):          
+               params = { "songID" : songid, "streamKey" : streamKey, "streamServerID" : streamServerID }
                self._callRemote("markSongComplete", params)
-
-       # Debug on off
-       def setDebug(self, state):
-               if state == True:
-                       self._apiDebug = True
-               else:
-                       self._apiDebug = False
-               if self._apiDebug == True:
-                       print "API debug is on"
                
        # Extract song data     
        def _parseSongs(self, items, limit=0):