From ac2e413ec03c68b39819292a3ecf28dadd61d470 Mon Sep 17 00:00:00 2001 From: David Eisner Date: Fri, 1 Nov 2013 09:27:31 +0000 Subject: [PATCH] Advertise MPD with Avahi A rudimentary implementation to resolve #39, ignoring dbus errors (just restart), name collisions (choose a fresh name), etc. --- mopidy/frontends/mpd/__init__.py | 2 ++ mopidy/frontends/mpd/actor.py | 26 ++++++++++++++++++++ mopidy/frontends/mpd/ext.conf | 2 ++ mopidy/frontends/mpd/zeroconf.py | 42 ++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 mopidy/frontends/mpd/zeroconf.py diff --git a/mopidy/frontends/mpd/__init__.py b/mopidy/frontends/mpd/__init__.py index 276be450..28f9c951 100644 --- a/mopidy/frontends/mpd/__init__.py +++ b/mopidy/frontends/mpd/__init__.py @@ -23,6 +23,8 @@ class Extension(ext.Extension): schema['password'] = config.Secret(optional=True) schema['max_connections'] = config.Integer(minimum=1) schema['connection_timeout'] = config.Integer(minimum=1) + schema['zeroconf_enabled'] = config.Boolean() + schema['zeroconf_name'] = config.String() return schema def validate_environment(self): diff --git a/mopidy/frontends/mpd/actor.py b/mopidy/frontends/mpd/actor.py index 4d983b73..b48b2b65 100644 --- a/mopidy/frontends/mpd/actor.py +++ b/mopidy/frontends/mpd/actor.py @@ -17,6 +17,9 @@ class MpdFrontend(pykka.ThreadingActor, CoreListener): super(MpdFrontend, self).__init__() hostname = network.format_hostname(config['mpd']['hostname']) port = config['mpd']['port'] + self.config = config + self.hostname = hostname + self.port = port try: network.Server( @@ -36,8 +39,31 @@ class MpdFrontend(pykka.ThreadingActor, CoreListener): logger.info('MPD server running at [%s]:%s', hostname, port) + def on_start(self): + try: + if self.config['mpd']['zeroconf_enabled']: + name = self.config['mpd']['zeroconf_name'] + import re + lo = re.search('(?