diff --git a/pulseaudio_dlna/pulseaudio.py b/pulseaudio_dlna/pulseaudio.py index 1dd60562..72ac0e4c 100644 --- a/pulseaudio_dlna/pulseaudio.py +++ b/pulseaudio_dlna/pulseaudio.py @@ -38,6 +38,15 @@ logger = logging.getLogger('pulseaudio_dlna.pulseaudio') +try: + with open('/var/lib/dbus/machine-id', 'r') as f: + MACHINE_ID = unicode(f.readline().strip()) +except: + MACHINE_ID = None + logger.warning('Could not determine the pulseaudio machine-id!') + +logger.info('MACHINE_ID: {}'.format(MACHINE_ID)) + class PulseAudio(object): def __init__(self): @@ -118,9 +127,10 @@ def retry_on_fail(method, tries=5): if retry_on_fail(self.update_playback_streams) and \ retry_on_fail(self.update_sinks): for stream in self.streams: - for sink in self.sinks: - if sink.object_path == stream.device: - sink.streams.append(stream) + if stream.is_local_stream: + for sink in self.sinks: + if sink.object_path == stream.device: + sink.streams.append(stream) else: logger.error( 'Could not update sinks and streams. This normally indicates ' @@ -208,12 +218,14 @@ def new(self, bus, client_path): name_bytes = properties.get('application.name', []) icon_bytes = properties.get('application.icon_name', []) binary_bytes = properties.get('application.process.binary', []) + machine_id_bytes = properties.get('application.process.machine_id', []) return PulseClient( object_path=unicode(client_path), index=unicode(obj.Get('org.PulseAudio.Core1.Client', 'Index')), name=self._convert_bytes_to_unicode(name_bytes), icon=self._convert_bytes_to_unicode(icon_bytes), binary=self._convert_bytes_to_unicode(binary_bytes), + machine_id=self._convert_bytes_to_unicode(machine_id_bytes), ) except dbus.exceptions.DBusException: logger.error( @@ -227,7 +239,7 @@ class PulseClient(object): __shared_state = {} - def __init__(self, object_path, index, name, icon, binary): + def __init__(self, object_path, index, name, icon, binary, machine_id): if object_path not in self.__shared_state: self.__shared_state[object_path] = {} self.__dict__ = self.__shared_state[object_path] @@ -237,6 +249,7 @@ def __init__(self, object_path, index, name, icon, binary): self.name = name or 'unknown' self.icon = icon or 'unknown' self.binary = binary or 'unknown' + self.machine_id = machine_id def __eq__(self, other): return self.object_path == other.object_path @@ -439,6 +452,14 @@ def __init__(self, object_path, index, device, client): self.device = device self.client = client + @property + def is_local_stream(self): + logger.info('{} | {} = {}'.format( + self.object_path, self.client.machine_id, MACHINE_ID)) + if not MACHINE_ID or self.client.machine_id == MACHINE_ID: + return True + return False + def switch_to_source(self, index): cmd = [ 'pactl', @@ -695,7 +716,7 @@ def __handle_sink_update(self, sink_path): return for bridge in self.bridges: - logger.debug('\n{}'.format(bridge)) + logger.info('\n{}'.format(bridge)) if bridge.device.state == bridge.device.PLAYING: if len(bridge.sink.streams) == 0 and ( not self.disable_device_stop and