Beispiel #1
0
    def from_string(self, metadataString):
        self.streamContent = ''
        self.radioShowMd = ''
        self.albumArtURI = ''
        self.album = ''
        elt = parse_xml(metadataString)
        elt = elt.getroot()

        streamContent_elt = find(elt, 'rcnw', 'streamContent')
        radioShowMd_elt = find(elt, 'rcnw', 'radioShowMd')
        albumArtURI_elt = find(elt, 'upnp', 'albumArtURI')
        album_elt = find(elt, 'upnp', 'album')

#        print str(streamContent_elt)
#        print str(radioShowMd_elt)
#        print str(albumArtURI_elt)
#        print str(album_elt)

        if streamContent_elt != None:
            self.streamContent = streamContent_elt.text
        if radioShowMd_elt != None:
            self.radioShowMd = radioShowMd_elt.text
        if albumArtURI_elt != None:
            self.albumArtURI = albumArtURI_elt.text
        if album_elt != None:
            self.album = album_elt.text
Beispiel #2
0
def process_page(xml):
    elt = parse_xml(xml)
    elt = elt.getroot()
    if elt.tag == 'lfm' and elt.get('status') == "ok":
        rt = elt.find('recenttracks')
        tracks = []
        for trackentry in rt.findall('track'):
            track = artist = album = date = ''
            ar = trackentry.find('artist')
            if ar != None:
                artist = ar.text
            tr = trackentry.find('name')
            if tr != None:
                track = tr.text
            al = trackentry.find('album')
            if al != None:
                album = al.text
            da = trackentry.find('date')
            if da != None:
                date = da.text
                ptime = da.get('uts')
            tracks.append((ptime, track, album, artist))
        return tracks
    else:
        return None
Beispiel #3
0
 def process_zgt(self, sid, node, nodedict):
     if 'ZoneGroupState' in nodedict:
         xml = nodedict['ZoneGroupState']
         elt = parse_xml(xml)
         elt = elt.getroot()
         out = node + ' ZoneGroupTopology\n'
         self.zone_groups[sid] = {}
         self.zone_group_coordinators_lookup[sid] = {}
         for e in elt.findall('ZoneGroup'):
             zg_tag = e.tag
             zg_coord = e.get('Coordinator')
             zone_group_members = []            
             for child in e.findall('ZoneGroupMember'):
                 zgm_tag = child.tag
                 zgm_uuid = child.get('UUID')
                 zgm_zonename = child.get('ZoneName')
                 zone_group_members.append((zgm_uuid, zgm_zonename))
                 if zgm_uuid == zg_coord:
                     zg_coord_name = zgm_zonename
             out += '    ' + 'Coordinator ' + zg_coord_name + '\n'
             zgm = []
             for m in zone_group_members:
                 uuid, name = m
                 out += '        ' + 'Member ' + name + '\n'
                 zgm.append(uuid)
                 self.zone_group_coordinators_lookup[sid][uuid] = zg_coord
             self.zone_groups[sid][zg_coord] = zgm
         out += '\n'
         if self.options.verbose:
             self.write_log2(out)
Beispiel #4
0
    def from_string(self, metadataString):
        self.streamContent = ''
        self.radioShowMd = ''
        self.albumArtURI = ''
        self.album = ''
        elt = parse_xml(metadataString)
        elt = elt.getroot()

        streamContent_elt = find(elt, 'rcnw', 'streamContent')
        radioShowMd_elt = find(elt, 'rcnw', 'radioShowMd')
        albumArtURI_elt = find(elt, 'upnp', 'albumArtURI')
        album_elt = find(elt, 'upnp', 'album')

        #        print str(streamContent_elt)
        #        print str(radioShowMd_elt)
        #        print str(albumArtURI_elt)
        #        print str(album_elt)

        if streamContent_elt != None:
            self.streamContent = streamContent_elt.text
        if radioShowMd_elt != None:
            self.radioShowMd = radioShowMd_elt.text
        if albumArtURI_elt != None:
            self.albumArtURI = albumArtURI_elt.text
        if album_elt != None:
            self.album = album_elt.text
Beispiel #5
0
def process_page(xml):
    elt = parse_xml(xml)
    elt = elt.getroot()
    if elt.tag == 'lfm' and elt.get('status') == "ok":
        rt = elt.find('recenttracks')
        tracks = []
        for trackentry in rt.findall('track'):
            track = artist = album = date = ''
            ar = trackentry.find('artist')
            if ar != None:
                artist = ar.text
            tr = trackentry.find('name')
            if tr != None:
                track = tr.text
            al = trackentry.find('album')
            if al != None:
                album = al.text
            da = trackentry.find('date')
            if da != None:
                date = da.text
                ptime = da.get('uts')
            tracks.append((ptime, track, album, artist))
        return tracks
    else:
        return None
Beispiel #6
0
def parse_soap_call(data):
    """ Parses a soap call and returns a 4-tuple.

    @param data: raw soap XML call data
    @type data: string

    @return: 4-tuple (method_name, args, kwargs, namespace)
    @rtype: tuple
    """
    tree = parse_xml(data)
    body = tree.find('{http://schemas.xmlsoap.org/soap/envelope/}Body')
    method = body.getchildren()[0]
    
    method_name = method.tag
    ns = None

    if method_name.startswith('{') and method_name.rfind('}') > 1:
        ns, method_name = method_name[1:].split('}')

#    print "ns, method"
#    print ns
#    print method

    args = []
    kwargs = {}
    for child in method.getchildren():

#        print "child"
#        print child
#        print child.tag
        kwargs[child.tag] = __decode_result(child)
        args.append(kwargs[child.tag])

    return method_name, args, kwargs, ns
Beispiel #7
0
def parse_soap_call(data):
    """ Parses a soap call and returns a 4-tuple.

    @param data: raw soap XML call data
    @type data: string

    @return: 4-tuple (method_name, args, kwargs, namespace)
    @rtype: tuple
    """
    tree = parse_xml(data)
    body = tree.find('{http://schemas.xmlsoap.org/soap/envelope/}Body')
    method = body.getchildren()[0]

    method_name = method.tag
    ns = None

    if method_name.startswith('{') and method_name.rfind('}') > 1:
        ns, method_name = method_name[1:].split('}')


#    print "ns, method"
#    print ns
#    print method

    args = []
    kwargs = {}
    for child in method.getchildren():

        #        print "child"
        #        print child
        #        print child.tag
        kwargs[child.tag] = __decode_result(child)
        args.append(kwargs[child.tag])

    return method_name, args, kwargs, ns
Beispiel #8
0
    def parse_result(self, data):

        print "??????????????????????????????????"
        print "parse_result"
        print data

        kwargs = {}
        collectionargs = []

        tree = parse_xml(data)
        body = tree.find(self.soapns + 'Body')
        method = body.getchildren()[0]
        
        if method.tag == self.soapns + 'Fault':
            # error returned from Napster
            '''
            <soap:Fault>
                <faultcode>soap:Server</faultcode>
                <faultstring>Can't use an undefined value as an ARRAY reference at /mp3/tools/napster-glueware/lib/Napster/DataObject/Radio.pm line 618.</faultstring>
            </soap:Fault>
            '''
            # rather than display returned message, announce unable to browse

            kwargs[self.napsterns + 'index'] = '0'            
            kwargs[self.napsterns + 'count'] = '0'            
            kwargs[self.napsterns + 'total'] = '0'
            collectionargs.append(parse_xml(self.errormetadata).getroot())
            kwargs['collections'] = collectionargs
            kwargs['success'] = '0'
                        
            return kwargs
        
        result = method.getchildren()[0]

        for child in result.getchildren():
            if child.text != None:
                # TODO: find a better way to separate collections and literals
                kwargs[child.tag] = child.text
            else:
                collectionargs.append(child)
        kwargs['collections'] = collectionargs
        kwargs['success'] = '1'

        print kwargs

        return kwargs
Beispiel #9
0
def process_first(xml):
    elt = parse_xml(xml)
    elt = elt.getroot()
    pages = 0
    if elt.tag == 'lfm' and elt.get('status') == "ok":
        rt = elt.find('recenttracks')
        pages = int(rt.get('totalPages'))
    return pages
Beispiel #10
0
def process_first(xml):
    elt = parse_xml(xml)
    elt = elt.getroot()
    pages = 0
    if elt.tag == 'lfm' and elt.get('status') == "ok":
        rt = elt.find('recenttracks')
        pages = int(rt.get('totalPages'))
    return pages
Beispiel #11
0
    def parse_result(self, data):

        print "??????????????????????????????????"
        print "parse_result"
        print data

        kwargs = {}
        collectionargs = []

        tree = parse_xml(data)
        body = tree.find(self.soapns + 'Body')
        method = body.getchildren()[0]

        if method.tag == self.soapns + 'Fault':
            # error returned from Napster
            '''
            <soap:Fault>
                <faultcode>soap:Server</faultcode>
                <faultstring>Can't use an undefined value as an ARRAY reference at /mp3/tools/napster-glueware/lib/Napster/DataObject/Radio.pm line 618.</faultstring>
            </soap:Fault>
            '''
            # rather than display returned message, announce unable to browse

            kwargs[self.napsterns + 'index'] = '0'
            kwargs[self.napsterns + 'count'] = '0'
            kwargs[self.napsterns + 'total'] = '0'
            collectionargs.append(parse_xml(self.errormetadata).getroot())
            kwargs['collections'] = collectionargs
            kwargs['success'] = '0'

            return kwargs

        result = method.getchildren()[0]

        for child in result.getchildren():
            if child.text != None:
                # TODO: find a better way to separate collections and literals
                kwargs[child.tag] = child.text
            else:
                collectionargs.append(child)
        kwargs['collections'] = collectionargs
        kwargs['success'] = '1'

        print kwargs

        return kwargs
Beispiel #12
0
    def parse_login_response(self, response):

        element = parse_xml(response)
        success = False
        for child in element.getiterator():
            if child.tag == '{http://www.sonos.com/Services/1.0}getUserIdResult':
                if child.text != None:
                    success = True        
                    self.userId = child.text
                    self.credentials = self.credentialsformat % self.userId

        return success
Beispiel #13
0
    def parse_login_response(self, response):

        element = parse_xml(response)
        success = False
        for child in element.getiterator():
            if child.tag == '{http://www.sonos.com/Services/1.0}getUserIdResult':
                if child.text != None:
                    success = True
                    self.userId = child.text
                    self.credentials = self.credentialsformat % self.userId

        return success
Beispiel #14
0
    def from_string(self, aString):
        #        print aString
        elt = parse_xml(aString)
        elt = elt.getroot()
        #        print "!!!!!!!!!!!!!!!!!!!!! AvailableServices from_string root - " + str(elt)
        for node in elt.getchildren():
            #            print "!!!!!!!!!!!!!!!!!!!!! AvailableServices from_string child - " + str(node)
            #            print "!!!!!!!!!!!!!!!!!!!!! AvailableServices from_string child - " + minidom.parseString(ElementTree.tostring(node)).toprettyxml()
            new_node = SonosService()
            new_node.from_element(node)
            self.add_item(new_node)

        return self
Beispiel #15
0
    def from_string(cls, xml_string):
        """ Returns an instance generated from a xml string.
        """

        # TODO: either fix this or remove it

        #        print "!!!!!!!!!!!!!!!!!!!! Object from_string"
        #        print cls
        #        print xml_string

        instance = cls()
        elt = parse_xml(xml_string)
        instance.from_element(elt.getroot())
        return instance
Beispiel #16
0
def print_node(xml_string):
    elt = parse_xml(xml_string)
    elt = elt.getroot()
    for e in elt.findall('*'):
        tag = e.tag
        val = e.get('val')
        if val == None: val = ''
        print "%s : %s" % (tag, val)
        for child in e.findall('*'):
            nodename = child.tag
            val = child.get('val')
            print str(nodename) + " = " + str(val)
            # check for metadata associated with tag
            if nodename.endswith('MetaData'):
                if val != '' and val != 'NOT_IMPLEMENTED':
                    if val.endswith('</DIDL-Lite>'):
                        eitem = print_node(val)
                        if eitem:
                            for child in eitem.findall('*'):
                                nodename = child.tag
                                val = child.get('val')
                                print str(nodename) + " = " + str(val)
Beispiel #17
0
def print_node(xml_string):
    elt = parse_xml(xml_string)
    elt = elt.getroot()
    for e in elt.findall('*'):
        tag = e.tag
        val = e.get('val')
        if val == None: val = ''
        print "%s : %s" % (tag, val)
        for child in e.findall('*'):
            nodename = child.tag
            val = child.get('val')
            print str(nodename) + " = " + str(val)
            # check for metadata associated with tag
            if nodename.endswith('MetaData'):
                if val != '' and val != 'NOT_IMPLEMENTED':
                    if val.endswith('</DIDL-Lite>'):
                        eitem = print_node(val)
                        if eitem:
                            for child in eitem.findall('*'):
                                nodename = child.tag
                                val = child.get('val')
                                print str(nodename) + " = " + str(val)
Beispiel #18
0
def parse_soap_fault(data):
    """ Parses a soap call and returns a 4-tuple.

    @param data: raw soap XML call data
    @type data: string

    @return: 4-tuple (method_name, args, kwargs, namespace)
    @rtype: tuple
    """
    tree = parse_xml(data)
    body = tree.find('{http://schemas.xmlsoap.org/soap/envelope/}Body')
    method = body.getchildren()[0]

    method_name = method.tag
    ns = None

    if method_name.startswith('{') and method_name.rfind('}') > 1:
        ns, method_name = method_name[1:].split('}')

    args = []
    kwargs = {}
    for child in method.getchildren():

        kwargs[child.tag] = __decode_result(child)

        if child.tag == 'detail':
            UPnPError = child.find(
                '{urn:schemas-upnp-org:control-1-0}UPnPError')
            errorCode = UPnPError.find(
                '{urn:schemas-upnp-org:control-1-0}errorCode')
            errorCodeText = errorCode.text
            errorCode = int(errorCodeText)
            errorDescription = UPNPERRORS.get(errorCode, '')
            kwargs[child.tag] = errorCodeText + " - " + errorDescription

        args.append(kwargs[child.tag])

    return method_name, args, kwargs, ns
Beispiel #19
0
def parse_soap_fault(data):
    """ Parses a soap call and returns a 4-tuple.

    @param data: raw soap XML call data
    @type data: string

    @return: 4-tuple (method_name, args, kwargs, namespace)
    @rtype: tuple
    """
    tree = parse_xml(data)
    body = tree.find('{http://schemas.xmlsoap.org/soap/envelope/}Body')
    method = body.getchildren()[0]

    method_name = method.tag
    ns = None

    if method_name.startswith('{') and method_name.rfind('}') > 1:
        ns, method_name = method_name[1:].split('}')

    args = []
    kwargs = {}
    for child in method.getchildren():

        kwargs[child.tag] = __decode_result(child)

        if child.tag == 'detail':
            UPnPError = child.find(
                '{urn:schemas-upnp-org:control-1-0}UPnPError')
            errorCode = UPnPError.find(
                '{urn:schemas-upnp-org:control-1-0}errorCode')
            errorCodeText = errorCode.text
            errorCode = int(errorCodeText)
            errorDescription = UPNPERRORS.get(errorCode, '')
            kwargs[child.tag] = errorCodeText + " - " + errorDescription

        args.append(kwargs[child.tag])

    return method_name, args, kwargs, ns
Beispiel #20
0
def parse_soap_call(data):
    """ Parses a soap call and returns a 4-tuple.

    @param data: raw soap XML call data
    @type data: string

    @return: 4-tuple (method_name, args, kwargs, namespace)
    @rtype: tuple
    """
    args = []
    kwargs = {}
    ns = "http://schemas.xmlsoap.org/soap/envelope/"
    tree = parse_xml(data)
    header = tree.find('{%s}Header' % ns)
    kwargs['__header__'] = {}
    if header:
    	for e in list(header):
	    kwargs['__header__'][e.tag] = {}
	    for se in list(e):
	        kwargs['__header__'][e.tag][se.tag] = {}
	        kwargs['__header__'][e.tag][se.tag]['__value__'] = __decode_result(se)
	        kwargs['__header__'][e.tag][se.tag]['__attrib__'] = se.attrib

    body = tree.find('{%s}Body' % ns)
    method = body.getchildren()[0]
    method_name = method.tag
    ns = None

    if method_name.startswith('{') and method_name.rfind('}') > 1:
        ns, method_name = method_name[1:].split('}')

    for child in method.getchildren():
        kwargs[child.tag] = __decode_result(child)
        args.append(kwargs[child.tag])

    return method_name, args, kwargs, ns
Beispiel #21
0
 def process_thirdpartymediaservers(self, thirdpartymediaservers):
     elt = self.from_string(thirdpartymediaservers)
     mediaservers = {}
     databases = {}
     ms = elt.findall('MediaServer')
     for entry in ms:
         udn = entry.attrib['UDN']
         mediaservers[udn] = entry.attrib['Name']
         location = entry.attrib['Location']
         dbname = ''
         xml = urllib.urlopen(location).read()
         elt = parse_xml(xml)
         if elt != None:
             root = elt.getroot()
             ns = "{urn:schemas-upnp-org:device-1-0}"
             self.remove_namespace(root, ns)
             if root != None:
                 dev = root.find('device')
                 if dev != None:
                     serialNumber = dev.find('serialNumber')
                     if serialNumber != None:
                         dbname = serialNumber.text
         databases[udn] = dbname
     return (mediaservers, databases)
Beispiel #22
0
def parse_soap_call(data):
    """ Parses a soap call and returns a 4-tuple.

    @param data: raw soap XML call data
    @type data: string

    @return: 4-tuple (method_name, args, kwargs, namespace)
    @rtype: tuple
    """
    args = []
    kwargs = {}
    ns = "http://schemas.xmlsoap.org/soap/envelope/"
    tree = parse_xml(data)
    header = tree.find('{%s}Header' % ns)
    kwargs['__header__'] = {}
    if header:
        for e in list(header):
            kwargs['__header__'][e.tag] = {}
            for se in list(e):
                kwargs['__header__'][e.tag][se.tag] = {}
                kwargs['__header__'][e.tag][se.tag]['__value__'] = __decode_result(se)
                kwargs['__header__'][e.tag][se.tag]['__attrib__'] = se.attrib

    body = tree.find('{%s}Body' % ns)
    method = body.getchildren()[0]
    method_name = method.tag
    ns = None

    if method_name.startswith('{') and method_name.rfind('}') > 1:
        ns, method_name = method_name[1:].split('}')

    for child in method.getchildren():
        kwargs[child.tag] = __decode_result(child)
        args.append(kwargs[child.tag])

    return method_name, args, kwargs, ns
Beispiel #23
0
 def from_string(self, aString):
     elt = parse_xml(aString)
     elt = elt.getroot()
     return elt