How to use the soco.utils.camel_to_underscore function in soco

To help you get started, we’ve selected a few soco examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SoCo / SoCo / soco / events_base.py View on Github external
instance = last_change_tree.find(
                    "{urn:schemas-upnp-org:metadata-1-0/AVT/}InstanceID")
                if instance is None:
                    instance = last_change_tree.find(
                        "{urn:schemas-upnp-org:metadata-1-0/RCS/}InstanceID")
                if instance is None:
                    instance = last_change_tree.find(
                        "{urn:schemas-sonos-com:metadata-1-0/Queue/}QueueID")
                # Look at each variable within the LastChange event
                for last_change_var in instance:
                    tag = last_change_var.tag
                    # Remove any namespaces from the tags
                    if tag.startswith('{'):
                        tag = tag.split('}', 1)[1]
                    # Un-camel case it
                    tag = camel_to_underscore(tag)
                    # Now extract the relevant value for the variable.
                    # The UPnP specs suggest that the value of any variable
                    # evented via a LastChange Event will be in the 'val'
                    # attribute, but audio related variables may also have a
                    # 'channel' attribute. In addition, it seems that Sonos
                    # sometimes uses a text value instead: see
                    # http://forums.sonos.com/showthread.php?t=34663
                    value = last_change_var.get('val')
                    if value is None:
                        value = last_change_var.text
                    # If DIDL metadata is returned, convert it to a music
                    # library data structure
                    if value.startswith('
github SoCo / SoCo / soco / music_services / data_structures.py View on Github external
# Check for invalid fields
            if key not in self._valid_fields:
                message = ('%s instantiated with invalid field "%s" and '
                           'value: %s')
                # Really wanted to raise exceptions here, but as it
                # turns out I have already encountered invalid fields
                # from music services.
                _LOG.debug(message, self.__class__, key, metadata_dict[key])

        # Convert names and create metadata dict
        self.metadata = {}
        for key, value in metadata_dict.items():
            if key in self._types:
                convertion_callable = self._types[key]
                value = convertion_callable(value)
            self.metadata[camel_to_underscore(key)] = value
github SoCo / SoCo / soco / core.py View on Github external
search = search_translation[search_type]
        response = self.contentDirectory.Browse([
            ('ObjectID', search),
            ('BrowseFlag', 'BrowseDirectChildren'),
            ('Filter', '*'),
            ('StartingIndex', start),
            ('RequestedCount', max_items),
            ('SortCriteria', '')
            ])

        dom = XML.fromstring(really_utf8(response['Result']))

        # Get result information
        out = {'item_list': [], 'search_type': search_type}
        for tag in ['NumberReturned', 'TotalMatches', 'UpdateID']:
            out[camel_to_underscore(tag)] = int(response[tag])

        # Parse the results
        #result_xml = XML.fromstring(really_utf8(dom.findtext('.//Result')))
        for container in dom:
            item = get_ml_item(container)
            # Append the item to the list
            out['item_list'].append(item)

        return out
github SoCo / SoCo / soco / core.py View on Github external
implementation
        """
        queue = []
        response = self.contentDirectory.Browse([
            ('ObjectID', 'Q:0'),
            ('BrowseFlag', 'BrowseDirectChildren'),
            ('Filter', '*'),
            ('StartingIndex', start),
            ('RequestedCount', max_items),
            ('SortCriteria', '')
        ])
        result = response['Result']

        metadata = {}
        for tag in ['NumberReturned', 'TotalMatches', 'UpdateID']:
            metadata[camel_to_underscore(tag)] = int(response[tag])

        # I'm not sure this necessary (any more). Even with an empty queue,
        # there is still a result object. This shoud be investigated.
        if not result:
            # pylint: disable=star-args
            return Queue(queue, **metadata)

        items = from_didl_string(result)
        for item in items:
            # Check if the album art URI should be fully qualified
            if full_album_art_uri:
                self.music_library._update_album_art_to_full_uri(item)
            queue.append(item)

        # pylint: disable=star-args
        return Queue(queue, **metadata)
github SoCo / SoCo / soco / ms_data_structures.py View on Github external
jpg
             true
             true
             true
           
         
        """
        # Add a few extra pieces of information
        content = {'description': service.description,
                   'service_id': service.service_id,
                   'parent_id': parent_id}
        # Extract values from the XML
        all_text_elements = tags_with_text(xml)
        for item in all_text_elements:
            tag = item.tag[len(NAMESPACES['ms']) + 2:]  # Strip namespace
            tag = camel_to_underscore(tag)  # Convert to nice names
            if tag not in cls.valid_fields:
                message = 'The info tag \'{}\' is not allowed for this item'.\
                    format(tag)
                raise ValueError(message)
            content[tag] = item.text

        # Convert values for known types
        for key, value in content.items():
            if key == 'duration':
                content[key] = int(value)
            if key in ['can_play', 'can_skip', 'can_add_to_favorites',
                       'can_enumerate']:
                content[key] = (value == 'true')
        # Rename a single item
        content['item_id'] = content.pop('id')
        # And get the extended id