1717def getstr (strid ): return interface .getstr (strid )
1818
1919REDIRECT_URI = "http://simkl.com"
20- USERFILE = xbmc .translatePath ("special://profile/simkl_key" )
20+ USERFILE = xbmc .translatePath (__addon__ .getAddonInfo ("profile" )).decode ("utf-8" ) + "simkl_key"
21+ xbmc .translatePath ("special://profile/simkl_key" )
22+
2123if not os .path .exists (USERFILE ):
2224 with open (USERFILE , "w" ) as f :
2325 f .write ("" )
2426else :
2527 with open (USERFILE , "r" ) as f :
26- print ( xbmc .log ("Simkl Userfile " + str (f .read () )))
28+ xbmc .log ("Simkl Userfile " + str (f .read ()))
2729
2830with open (os .path .dirname (os .path .realpath (__file__ )).strip ("lib" ) + "data/apikey" ) as f :
2931 d = json .loads (f .read ())
@@ -119,6 +121,7 @@ def lock(self, fname, duration):
119121 exp = self .scrobbled_dict
120122 exp [fname ] = int (time .time () + (105 - float (__addon__ .getSetting ("scr-pct" ))) / 100 * duration )
121123 xbmc .log ("Simkl: Locking {}" .format (exp ))
124+ self .scrobbled_dict = {fname :exp [fname ]} #So there is always only one entry on the dict
122125
123126 def is_locked (self , fname ):
124127 exp = self .scrobbled_dict
@@ -149,9 +152,10 @@ def watched(self, filename, mediatype, duration, date=time.strftime('%Y-%m-%d %H
149152 values = json .dumps (values )
150153 xbmc .log ("Simkl: Query: {}" .format (values ))
151154 con .request ("GET" , "/search/file/" , body = values , headers = headers )
152- r1 = con .getresponse ().read ().decode ("utf-8" )
155+ r1 = con .getresponse ().read ()# .decode("utf-8")
153156 xbmc .log ("Simkl: Response: {}" .format (r1 ))
154- r = json .loads (r1 )
157+ r = json .loads (str (r1 ))
158+ self .lastwatched = r
155159 if r == []:
156160 xbmc .log ("Simkl: Couldn't scrobble: Null Response" )
157161 return 0
@@ -178,10 +182,10 @@ def watched(self, filename, mediatype, duration, date=time.strftime('%Y-%m-%d %H
178182 xbmc .log ("Simkl: {}" .format ("ERROR: httplib.BadStatusLine" ))
179183 except SSLError : #Fix #8
180184 xbmc .log ("Simkl: ERROR: SSLError, retrying?" )
181- if cnt == 0 : interface .notify ("Error at scrobbling. Try number %s" % cnt + 1 )
185+ if cnt == 0 : interface .notify (getstr ( 32029 ). format ( cnt + 1 ) )
182186 if cnt <= 3 :
183187 self .watched (filename , mediatype , duration , date = date , cnt = cnt + 1 )
184- else : interface .notify ("I give up :( " )
188+ else : interface .notify ("SSLError " )
185189
186190 else :
187191 xbmc .log ("Simkl: Can't scrobble. User not logged in or file locked" )
@@ -191,6 +195,4 @@ def watched(self, filename, mediatype, duration, date=time.strftime('%Y-%m-%d %H
191195if __name__ == "__main__" :
192196 if sys .argv [1 ] == "login" :
193197 xbmc .log ("Logging in" , level = xbmc .LOGDEBUG )
194- api .login ()
195- if sys .argv [1 ] == "test" :
196- api .scrobble_from_filename ("South Park S01E02" )
198+ api .login ()
0 commit comments