scrobd scrobd
A tiny scrobbler for MPD that support both last.fm and libre.fm

Browse the code

Differences between 32 and 33 on /.
Number of edited files: 1 (0 added, 0 deleted and 1 modified)
Author: chickenzilla
Log message: Correction du problème de reconnexion trop fréquente à libre.fm
Date: 2009-07-03 12:20:08

Added file(s) Deleted file(s) Modified file(s)

 

Old New Code
19 19

                                        
20 20
# TODO :
21 21
# - multiple submission when sendall => change scrobbler2 for this
  22
# - change the excepts : not all errors are deconnections
22 23
# - clean the encoding functions
23 24
from __future__ import with_statement
24 25

                                        
47 48

                                        
48 49
import locale
49 50
import codecs
50  
import unicodedata
  51
from unicodedata import normalize
51 52

                                        
52 53
CLIENT_ID = "srd"
53 54
CLIENT_VERSION = __version__
120 121
        except SocketError, err:
121 122
            self.connected = False
122 123
            self.log_error(_("Unable to connect to the MPD server : %s") %
123  
                    unicode(err.args[0], "utf-8"))
  124
                    unicode(err.args[0].args[1], "utf-8"))
124 125
        return False
125 126

                                        
126 127
    def connection_handler(self):
268 269
        except scrobbler2.ProtocolError, err:
269 270
            from re import findall
270 271
            a = findall(r"\d+", str(err))
271  
            self.scrobbler.connected = time.time() + (int(a[0]) if a else
272  
                    self.scrobbler.reconnect_delay)
  272
            self.scrobbler.connected = time.time() + (int(a[0] if a else
  273
                    self.scrobbler.reconnect_delay * 60))
273 274

                                        
274 275
        if state:
275 276
            self.scrobbler.log_info(_("Success !\n"), date=False)
283 284
    This class manage a scrobbler, the cache associated and the connexion
284 285
    failures, followed by a reconnection.
285 286
    """
286  
    def __init__(self, config, log_info, log_error, config_glob,
287  
            reconnect_delay=60):
  287
    def __init__(self, config, log_info, log_error, config_glob):
288 288
        """
289 289
        config is the scrobbler scpecific configuration,
290 290
        log_error and log_info are functions
294 294
        self.address = config["address"]
295 295
        self.user = config["user"]
296 296
        self.password = config["password"]
  297
        self.config = config_glob
297 298
        if not self.user and not self.config.fork:
298 299
            self.user = raw_input(_("User name for %s : ") % self.address)
299 300
        if not self.password and not self.config.fork:
300 301
            self.password = md5(getpass(_("Password for %s : ") %
301 302
                self.address)).hexdigest()
302  
        self.config = config_glob
303 303
        self.log_error = log_error
304 304
        self.log_info = log_info
305  
        self.reconnect_delay = reconnect_delay
  305
        self.reconnect_delay = config_glob.reconnect_delay
306 306
        self.queue = list()
307 307
        self.flags = {"connecting":False}
308 308
        self.thread = None
397 397
        if not self.connection_handler():
398 398
            return False
399 399
        try: # TODO séparer excepts
400  
            n = scrobbler2.Scrobbler.now_playing(self,
401  
                    **song.format_now_playing())
  400
            if song["artist"] and song["title"]:
  401
                n = scrobbler2.Scrobbler.now_playing(self,
  402
                        **song.format_now_playing())
  403
            else:
  404
                return False
402 405
        except (scrobbler2.BackendError, scrobbler2.PostError,
403 406
                scrobbler2.SessionError, URLError), err:
404 407
            self.set_connected(False)
465 468
        if connected:
466 469
            self.connected = -1
467 470
        else:
468  
            self.connected = time.time() + self.reconnect_delay
  471
            self.connected = time.time() + self.reconnect_delay * 60
469 472
# }}}
470 473

                                        
471 474

                                        
496 499

                                        
497 500
    def summary(self):
498 501
        return (self["artist"], self["title"])
  502

                                    
499 503
    def set_mbid(self, log_fun=None):
500 504
        self["mbid"] = retrieve_mb_id(self["artist"], self["title"])
501 505
        if self["mbid"] and log_fun:
575 579
        self.info_file = os.getcwd()+"/infos.log"
576 580
        self.pid_file = os.getcwd()+"/scrobd.pid"
577 581
        self.cache_dir = os.getcwd()+"/cache/"
  582
        self.reconnect_delay = 5
578 583
        self.refresh_delay = 5
579 584
        self.config_file = os.path.expanduser("~/.scrobdrc")
580 585
        self.scrobblers = []
838 843
    s = unicode(s, "utf8")
839 844
    out = ""
840 845
    for c in s:
841  
        c = unicodedata.normalize('NFKD', c)[0]
  846
        c = normalize('NFKD', c)[0]
842 847
        if c in u2a:
843 848
            out += u2a[c]
844 849
        if ord(c) <= 127:
845 850