X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=sima%2Fplugins%2Fcore%2Funiq.py;h=bc2ef547c41bfe7e5b6f2dc86ec8fecb3f29b97f;hb=bda454e619617e94303ddbad3601f5ee4fb2edc8;hp=0f42718ed992b89f8516788ea525e275269d773c;hpb=ac0d934fc127484a0ed14386e4c4ecd4f915b6ca;p=mpd-sima.git diff --git a/sima/plugins/core/uniq.py b/sima/plugins/core/uniq.py index 0f42718..bc2ef54 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 @@ -40,7 +41,7 @@ class Uniq(Plugin): def __init__(self, daemon): Plugin.__init__(self, daemon) - self.chan = 'mpd_sima:{0}.{1}'.format(getfqdn(), getpid()) + self.chan = None self.channels = [] self._registred = False @@ -53,11 +54,10 @@ class Uniq(Plugin): 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 @@ -70,9 +70,13 @@ class Uniq(Plugin): self.log.warning(' '.join(channels)) def sub_chan(self): - self.log.debug('Registering as {}'.format(self.chan)) - self.player.subscribe(self.chan) - self._registred = True + self.chan = 'mpd_sima:{0}.{1}'.format(getfqdn(), getpid()) + 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():