def _discover_devices(self): holder = pulseaudio_dlna.holder.Holder(self.PLUGINS) holder.search(ttl=5) logger.info('Found the following devices:') for udn, device in holder.devices.items(): logger.info(' - "{name}" ({flavour})'.format( name=device.name, flavour=device.flavour)) return holder.devices.values()
def create_device_config(self, update=False): logger.info('Starting discovery ...') holder = pulseaudio_dlna.holder.Holder(plugins=self.PLUGINS) holder.search(ttl=5) logger.info('Discovery complete.') def device_filter(obj): if hasattr(obj, 'to_json'): return obj.to_json() else: return obj.__dict__ def obj_to_dict(obj): json_text = json.dumps(obj, default=device_filter) return json.loads(json_text) if update: existing_config = self.read_device_config() if existing_config: new_config = obj_to_dict(holder.devices) new_config.update(existing_config) else: logger.error( 'Your device config could not be found at any of the ' 'locations "{}"'.format( ','.join(self.DEVICE_CONFIG_PATHS))) sys.exit(1) else: new_config = obj_to_dict(holder.devices) json_text = json.dumps(new_config, indent=4) for config_path in reversed(self.DEVICE_CONFIG_PATHS): config_file = os.path.join(config_path, self.DEVICE_CONFIG) if not os.path.exists(config_path): try: os.makedirs(config_path) except (OSError, IOError): continue try: with open(config_file, 'w') as h: h.write(json_text.encode(self.ENCODING)) logger.info('Found the following devices:') for device in holder.devices.values(): logger.info('{name} ({flavour})'.format( name=device.name, flavour=device.flavour)) for codec in device.codecs: logger.info(' - {}'.format( codec.__class__.__name__)) logger.info( 'Your config was successfully written to "{}"'.format( config_file)) return except (OSError, IOError): continue logger.error( 'Your device config could not be written to any of the ' 'locations "{}"'.format(','.join(self.DEVICE_CONFIG_PATHS)))
def create_device_config(self, update=False): logger.info('Starting discovery ...') holder = pulseaudio_dlna.holder.Holder(plugins=self.PLUGINS) holder.search(ttl=5) logger.info('Discovery complete.') def device_filter(obj): if hasattr(obj, 'to_json'): return obj.to_json() else: return obj.__dict__ def obj_to_dict(obj): json_text = json.dumps(obj, default=device_filter) return json.loads(json_text) if update: existing_config = self.read_device_config() if existing_config: new_config = obj_to_dict(holder.devices) new_config.update(existing_config) else: logger.error( 'Your device config could not be found at any of the ' 'locations "{}"'.format(','.join( self.DEVICE_CONFIG_PATHS))) sys.exit(1) else: new_config = obj_to_dict(holder.devices) json_text = json.dumps(new_config, indent=4) for config_path in reversed(self.DEVICE_CONFIG_PATHS): config_file = os.path.join(config_path, self.DEVICE_CONFIG) if not os.path.exists(config_path): try: os.makedirs(config_path) except (OSError, IOError): continue try: with open(config_file, 'w') as h: h.write(json_text.encode(self.ENCODING)) logger.info('Found the following devices:') for device in holder.devices.values(): logger.info('{name} ({flavour})'.format( name=device.name, flavour=device.flavour)) for codec in device.codecs: logger.info(' - {}'.format( codec.__class__.__name__)) logger.info( 'Your config was successfully written to "{}"'.format( config_file)) return except (OSError, IOError): continue logger.error('Your device config could not be written to any of the ' 'locations "{}"'.format(','.join( self.DEVICE_CONFIG_PATHS)))
def _discover_devices(self): holder = pulseaudio_dlna.holder.Holder(self.PLUGINS) holder.search(ttl=self.TIMEOUT) return holder.devices.values()