1 # -*- coding: utf-8 -*-
2 # Copyright (c) 2014 Jack Kaliko <kaliko@azylum.org>
4 # This file is part of sima
6 # sima is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # sima is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with sima. If not, see <http://www.gnu.org/licenses/>.
21 Publish presence on the MPD host message bus
23 Notifies when concurrent instance run on the same host.
26 # standard library import
28 from socket import getfqdn
30 # third parties components
33 from ...client import PlayerError
34 from ...lib.plugin import Plugin
39 Publish presence on the MPD host message bus
42 def __init__(self, daemon):
43 Plugin.__init__(self, daemon)
44 self.chan = 'mpd_sima:{0}.{1}'.format(getfqdn(), getpid())
46 self._registred = False
49 if not self.is_capable():
50 self.log.warning('MPD does not provide client to client')
53 if not self._registred:
57 if {'channels', 'subscribe'}.issubset(set(self.player.commands())):
58 # Groove Basin compatibility
59 # For some reason Groove Basin have channels command but no
60 # subscribe command‽
63 def get_channels(self):
64 return [chan for chan in self.player.channels() if
65 chan.startswith('mpd_sima') and chan != self.chan]
68 channels = self.get_channels()
70 self.log.warning('Another instance is queueing on this MPD host')
71 self.log.warning(' '.join(channels))
74 self.log.debug('Registering as {}'.format(self.chan))
76 self.player.subscribe(self.chan)
77 self._registred = True
78 except PlayerError as err:
79 self.log.error('Failed to register: %s', err)
81 def callback_need_track(self):
87 # vim: ai ts=4 sw=4 sts=4 expandtab