From 8c4f31db057d0110b27ca8cafee8ee0abc22b8d0 Mon Sep 17 00:00:00 2001 From: warwickh Date: Wed, 8 Sep 2021 16:47:08 +1000 Subject: [PATCH] More efficient settings and return value --- service.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/service.py b/service.py index a321a3f..ab7ad35 100644 --- a/service.py +++ b/service.py @@ -15,6 +15,7 @@ from simpleplugin import Addon plugin = Plugin() connection = None +scrobbleEnabled = Addon().get_setting('scrobble') scrobbled = False def get_connection(): @@ -48,9 +49,9 @@ def scrobble_track(track_id): connection = get_connection() if connection==False: - return + return False res = connection.scrobble(track_id) - xbmc.log("response %s"%(scrobble), xbmc.LOGINFO) + #xbmc.log("response %s"%(res), xbmc.LOGINFO) if res['status'] == 'ok': return True else: @@ -64,7 +65,7 @@ if __name__ == '__main__': break if (xbmc.getCondVisibility("Player.HasMedia")): try: - if(Addon().get_setting('scrobble')): + if(scrobbleEnabled): currentFileName = xbmc.getInfoLabel("Player.Filenameandpath") currentFileProgress = xbmc.getInfoLabel("Player.Progress") pattern = re.compile(r'plugin:\/\/plugin\.audio\.subsonic\/\?action=play_track&id=(.*?)&') @@ -74,8 +75,9 @@ if __name__ == '__main__': scrobbled = False elif (int(currentFileProgress)>=50 and scrobbled == False): xbmc.log("Scrobbling Track Id %s"%(currentTrackId), xbmc.LOGDEBUG) - scrobble_track(currentTrackId) - scrobbled = True + success = scrobble_track(currentTrackId) + if success: + scrobbled = True else: pass except Exception as e: