X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=sima%2Fplugins%2Fcore%2Funiq.py;h=60d1680ed174862817bdf830831ab9462d448eb1;hb=03b3fce479e480222a1161f56d6551f5b47e83b9;hp=1abdd62a8f492ee805f53f877afc4d34567f80ba;hpb=c88354dc91b4f22af14b70e2fa2654f2f57438e3;p=mpd-sima.git diff --git a/sima/plugins/core/uniq.py b/sima/plugins/core/uniq.py index 1abdd62..60d1680 100644 --- a/sima/plugins/core/uniq.py +++ b/sima/plugins/core/uniq.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2014 Jack Kaliko +# Copyright (c) 2014, 2020 kaliko # # This file is part of sima # @@ -30,6 +30,7 @@ from socket import getfqdn # third parties components # local import +from ...mpdclient import PlayerError from ...lib.plugin import Plugin @@ -42,21 +43,21 @@ class Uniq(Plugin): Plugin.__init__(self, daemon) self.chan = 'mpd_sima:{0}.{1}'.format(getfqdn(), getpid()) self.channels = [] - self.uniq = True + self._registred = False def start(self): if not self.is_capable(): self.log.warning('MPD does not provide client to client') return self.is_uniq() - self.sub_chan() + if not self._registred: + self.sub_chan() def is_capable(self): - if {'channels', 'subscribe'}.issubset(set(self.player.commands())): - # Groove Basin compatibility - # For some reason Groove Basin have channels command but no - # subscribe command‽ - return True + # Groove Basin compatibility + # For some reason Groove Basin have channels command but no + # subscribe command‽ + return {'channels', 'subscribe'}.issubset(set(self.player.commands())) def get_channels(self): return [chan for chan in self.player.channels() if @@ -67,11 +68,14 @@ class Uniq(Plugin): if channels: self.log.warning('Another instance is queueing on this MPD host') self.log.warning(' '.join(channels)) - self.uniq = False def sub_chan(self): - self.log.debug('Registering as {}'.format(self.chan)) - self.player.subscribe(self.chan) + self.log.debug('Registering as %s', self.chan) + try: + self.player.subscribe(self.chan) + self._registred = True + except PlayerError as err: + self.log.error('Failed to register: %s', err) def callback_need_track(self): if self.is_capable():