コード例 #1
0
ファイル: Discovery.py プロジェクト: AndyThirtover/wb_gateway
def UPnPDiscoverCheck():
    discovered = []
    log = logging.getLogger( "WebBrickGwConfig.Discovery.UpnpDiscoverCheck" )
    try:        
        address = "http://10.100.100.14:8080/eventstate/upnp/device/count"
        devicecount = urllib.urlopen(address)
        devicecount = devicecount.read()   
        devicecount = getDictFromXmlString(devicecount)
        log.debug(devicecount)
        devicecount = int(devicecount["value"]["val"]['']) 
        if devicecount > 0:
            for x in range(1,devicecount+1):
                address = "http://10.100.100.14:8080/eventstate/upnp/device/%i?attr=udn" %x
                udn  = urllib.urlopen(address)
                udn = udn.read()
                udn = getDictFromXmlString(udn)
                udn = str(udn["value"]["val"][''])
                
                address = "http://10.100.100.14:8080/eventstate/upnp/device/%i?attr=model" %x
                model  = urllib.urlopen(address)
                model = model.read()
                model = getDictFromXmlString(model)
                model = str(model["value"]["val"][''])
                
                discovered.append({"udn" : udn , "model" : model , "devicenumber" : x})
    except Exception , e:       
        log.exception( e )
コード例 #2
0
ファイル: UPNPBrisa.py プロジェクト: AndyThirtover/wb_gateway
 def _avt_event_callback(self, udn, name, value):
     self._log.debug( '%s update for device: %s' %(name,udn) )
     # TODO: Process event 
     
     if name == "LastChange":
         try:  
             last_change = getDictFromXmlString(str(value))
         except:
             print "no valid xml"
         try:
             last_change["Event"]["InstanceID"]["CurrentTrackMetaData"]["val"] = getDictFromXmlString(last_change["Event"]["InstanceID"]["CurrentTrackMetaData"]["val"])
         except:
             print "no valid xml 2"
         #try: 
         #    last_change["Event"]["InstanceID"]["r:NextTrackMetaData"]["val"] = getDictFromXmlString(last_change["Event"]["InstanceID"]["r:NextTrackMetaData"]["val"])
         #except:
         #    print "no valid xml 3"
         try: 
             title = last_change["Event"]["InstanceID"]["CurrentTrackMetaData"]["val"]["DIDL-Lite"]["item"]["dc:title"][""]
         except:
             print "no title"
             title = ""
             
         try: 
             artist = last_change["Event"]["InstanceID"]["CurrentTrackMetaData"]["val"]["DIDL-Lite"]["item"]["dc:creator"][""]
         except:
             print "no artist"
             artist = ""
             
         try: 
             album = last_change["Event"]["InstanceID"]["CurrentTrackMetaData"]["val"]["DIDL-Lite"]["item"]["upnp:album"][""]
         except:
             print "no album"
             album = ""
             
         try: 
             current_track = last_change["Event"]["InstanceID"]["CurrentTrack"]["val"]
         except:
             print "no current track"
             current_track = ""
             
         try: 
             no_of_tracks = last_change["Event"]["InstanceID"]["NumberOfTracks"]["val"]
         except:
             print "no number of tracks"
             no_of_tracks = ""
             
         try: 
             current_track_duration = last_change["Event"]["InstanceID"]["CurrentTrackDuration"]["val"]
         except:
             print "no duration"
             current_track_duration = ""
         try: 
             transport_state = last_change["Event"]["InstanceID"]["TransportState"]["val"]
         except:
             print "no transport state"
             transport_state = ""
         try: 
             current_play_mode = last_change["Event"]["InstanceID"]["CurrentPlayMode"]["val"]
         except:
             print "no playmode"
             current_play_mode = ""
             
         if transport_state == "PLAYING":
             playing = 1
             paused = 0
             stopped = 0
         elif transport_state == "PAUSED_PLAYBACK":
             playing = 0
             paused = 1
             stopped = 0
         elif transport_state == "STOPPED":
             playing = 0
             paused = 0
             stopped = 1
         else:
             print "no valid tarnsport state"
             playing = 0
             paused = 0
             stopped = 0
         
         if current_play_mode == "NORMAL":
             repeat = 0
             shuffle = 0
         elif current_play_mode == "REPEAT_ALL":
             repeat = 1
             shuffle = 0
         elif current_play_mode == "SHUFFLE_NOREPEAT":
             repeat = 0
             shuffle = 1
         elif current_play_mode == "SHUFFLE":
             repeat = 1
             shuffle = 1
         else:
             print "no valid playmode"
             repeat = 0
             shuffle = 0
             
         
             
         self.sendEvent( Event( "http://id.webbrick.co.uk/events/av/transport/state", 
             "av/transport/state/%s" %(udn), 
             { 'udn':udn, 
               'artist':artist,
               'album':album, 
               'title':title, 
               'albumarturi':"",
               'CurrentTrack':current_track,
               'NumberOfTracks':no_of_tracks,
               'CurrentTrackDuration':current_track_duration,
               'TransportState':transport_state,
               'playing':playing,
               'stopped':stopped,
               'paused':paused,
               'shuffle':shuffle,
               'repeat':repeat,
              } ) )
コード例 #3
0
ファイル: Discovery.py プロジェクト: AndyThirtover/wb_gateway
    def getParams(self, ipaddr):
        """
        function to return a dictonary of parameters of the exeterity box on the 
        given address.
        
        @params ipaddr: The IP address
        
        @type ipaddr: string 
        """
        
        result = None
        
        auth = 'Basic ' + 'YWRtaW46bGFicmFkb3I=\n'  # to obsure the default details
        conn = httplib.HTTPConnection(ipaddr)
        conn.putrequest("GET", "/cgi-bin/general.cgi")
        conn.putheader("Authorization", auth)
        conn.endheaders()
        response = conn.getresponse()
        general_html = None
        if response.status == 200:
            self._log.debug("Got /cgi-bin/general.cgi")
            general_html = response.read()
        else:
            #for newer exterity models general.cgi 404s so we have to do this
            conn.putrequest("GET", "/cgi-bin/general")
            conn.putheader("Authorization", auth)
            conn.endheaders()
            response = conn.getresponse()            
            if response.status == 200:
                self._log.debug("Got /cgi-bin/general")
                general_html = response.read()
        
        if general_html:
                
            result = dict()
            #encconf only exists on older SD encoders
            conn.putrequest("GET" , "/cgi-bin/encconf.cgi")
            conn.putheader("Authorization", auth)
            conn.endheaders()
            encoder_response = conn.getresponse()
            #decconf only exists on decoders
            conn.putrequest("GET" , "/cgi-bin/decconf.cgi")
            conn.putheader("Authorization", auth)
            conn.endheaders()
            decoder_response = conn.getresponse()
            #encoding_enc only exists on newer HD encoders
            conn.putrequest("GET" , "/cgi-bin/encoding_enc")
            conn.putheader("Authorization", auth)
            conn.endheaders()
            hd_encoder_response = conn.getresponse()
            self._log.debug("Page status on device : %s \n\t\t\tencconf.cgi : %s \n\t\t\tdecconf.cgi : %s \n\t\t\tencoding_enc : %s" %(ipaddr,encoder_response.status,decoder_response.status,hd_encoder_response.status))
            if encoder_response.status == 200:
                #general.cgi from an encoder is malformed on some firmware versions and has technically unsafe html in it
                #so we have to look for strings
                try:
                    temp_data = getDictFromXmlString(general_html)
                    result["name"] = temp_data["html"]["body"]["form"]["table"]["tr"][0]["td"][1]["input"]["value"]
                    result["location"] = temp_data["html"]["body"]["form"]["table"]["tr"][1]["td"][1]["input"]["value"]
                    result["ip"] = ipaddr
                    result["type"] = "encoder"
                except:
                    self._log.debug("Extertity encoder generated an unsafe html page, resorting to string searching")
                    #self._log.debug("HTML is %s" %general_html)
                    name_startstring = """<TD><INPUT NAME=Name TYPE=TEXT value="""
                    name_endstring = """"></TD>
</TR>
<TR>
<TD>Location:</TD>"""
                    namestart = general_html.find(name_startstring) + 1 #add one before there is a quotation mark after this THEN the name
                    nameend = general_html.find(name_endstring)
                    result["name"] = general_html[namestart + len(name_startstring):nameend]
                    
                    location_startstring = """<TD><INPUT NAME=Location TYPE=TEXT value="""
                    location_endstring = """"></TD>
</TR>
<TR>
<TD></TD>
<TD align=center><INPUT type="submit" value="Apply"></TD>
"""
                    locationstart = general_html.find(location_startstring) + 1 #add one before there is a quotation mark after this THEN the name
                    locationend = general_html.find(location_endstring)
                    result["location"] = general_html[locationstart + len(location_startstring):locationend]
                    #self._log.debug("Got encconf.cgi , general.cgi is %s" %general_html[bodystart:bodyend+7])
                result["ip"] = ipaddr
                result["type"] = "encoder"
                result["streamUrl"] = GetStreamUrl(ipaddr)
                
            elif decoder_response.status == 200:
                temp_data = getDictFromXmlString(general_html)
                result["name"] = temp_data["html"]["body"]["form"]["table"]["tr"][0]["td"][1]["input"]["value"]
                result["location"] = temp_data["html"]["body"]["form"]["table"]["tr"][1]["td"][1]["input"]["value"]
                result["ip"] = ipaddr
                result["type"] = "decoder"
            elif hd_encoder_response.status == 200:
                bodystart = general_html.find("<body")
                bodyend = general_html.find("</body>")
                temp_data = getDictFromXmlString(general_html[bodystart:bodyend+7])
                result["name"] = temp_data["body"]["form"]["table"][1]["tr"][0]["td"]["input"]["value"]
                result["location"] = temp_data["body"]["form"]["table"][1]["tr"][1]["td"]["input"]["value"]
                result["ip"] = ipaddr
                result["type"] = "encoder"
                result["streamUrl"] = GetStreamUrl(ipaddr)
            else:
                #neither page exist so this is an unencountered type of exterity device
                result = None
        return result
コード例 #4
0
 def zonegroup_update(self, variable):
     if variable.name == "ZoneGroupState" and variable.value:
         # variable.value is an XML fragment
         zgs = getDictFromXmlString(variable.value)
         self.debug("ZoneGroupState %s", zgs)