MPDScrobbler: some cleanup in cache handling
authorkaliko <kaliko.jack@azylum.org>
Wed, 2 Jan 2013 21:46:37 +0000 (22:46 +0100)
committerkaliko <kaliko.jack@azylum.org>
Wed, 2 Jan 2013 21:46:37 +0000 (22:46 +0100)
misc/MPDScrobbler/mpdscrobbler.py

index fe7bee7..95246d1 100755 (executable)
@@ -10,7 +10,7 @@ from collections import deque
 
 from client import scrobble
 
-from lib.mpdclient import Player, PlayerError
+from lib.mpdclient import Player
 from lib.daemon import Daemon
 
 import logging
@@ -67,12 +67,14 @@ class QueuManagement(threading.Thread):
         except URLError as err:
             logging.warning('Failed catching up with "%s": %s' % (track, err))
             self.queu.appendleft(track)
+            return False
         except Exception as err:
             logging.warning('Unhandled exception: %s' % err)
             self.queu.appendleft(track)
-        else:
-            self.queu.remove(track)
-            return True
+            return False
+        logging.info('Catching up with {0}'.format(track))
+        self.queu.remove(track)
+        return True
 
     def run(self):
         for i in xrange(len(self.queu_copy)):
@@ -103,6 +105,8 @@ class MpdScrobbler(Player):
             sys.exit(0)
 
     def scrobble(self):
+        if self.failed_sc_cache:
+            logging.info('Got %i in queu' % len(self.failed_sc_cache))
         logging.info(self.current_track)
         art = self.current_track.get_artist()
         tit = self.current_track.get_title()
@@ -125,8 +129,6 @@ class MpdScrobbler(Player):
             # Deal with the queu if last scrobble went fine
             if self.failed_sc_cache:
                 QueuManagement(self.failed_sc_cache).start()
-        if self.failed_sc_cache:
-            logging.info('Got %i in queu' % len(self.failed_sc_cache))
 
     def log_track(self):
         current = self.currentsong()