def command_09_doXbmc(self, user, message, args): """([Xx]bmc)\s+(switch|play|pause|what)( +(.*))?$(?i)""" action = args[1] try: print "args" print args if args[2] != None: target = args[2] target = target.lstrip() else: target = "all" except: pass try: if self.site is None: raise Exception("you must load asite that has xbmc devices.") # try to load the xbmcs if not self.x.xbmchosts: exec ("sitedevs=config.%s_devices" % self.site) for staticdevs in sitedevs: print staticdevs print "staticdevs above. adding devs to xbmc" try: if staticdevs["xbmc"]: pass except: continue try: print "step 99 staticdevs[xbmc] below" print staticdevs["xbmc"] # for key,val in staticdevs: # if key !="xbmc": # print "not adding xbmc devs" # print staticdevs # continue # else: # print "key is not xbmc" # print key for staticdev in staticdevs["xbmc"]: print "adding xbmc devs to hosts, xbmchosts below" self.x.xbmchosts.append( [ staticdev["hostname"], staticdev["username"], staticdev["password"], staticdev["port"], staticdev["label"], ] ) # self.replyMessage(user, "Loaded "+staticdev["label"]) except Exception, e: for i in e: self.replyMessage(user, "xbmchosts: " + e) pass if self.x.xbmchosts: print "success initing xbmc." # self.replyMessage(user,"Switching to "+self.x.xbmchosts[self.x.xbmcactive][4]) savehosts = self.x.xbmchosts self.x = xbmc( self.x.xbmchosts[self.x.xbmcactive][0], username=self.x.xbmchosts[self.x.xbmcactive][1], password=self.x.xbmchosts[self.x.xbmcactive][2], port=self.x.xbmchosts[self.x.xbmcactive][3], ) self.x.xbmchosts = savehosts self.x.xbmcactive = 0 print "xbmc connected!!" else: self.replyMessage(user, "Site doesn't have any xbmc hosts.") return else:
) self.x.xbmchosts = savehosts self.x.xbmcactive = 0 print "xbmc connected!!" else: self.replyMessage(user, "Site doesn't have any xbmc hosts.") return else: print "xbmchosts currently set, reconnecting" print self.x.xbmchosts savehosts = self.x.xbmchosts saveactive = self.x.xbmcactive self.x = xbmc( self.x.xbmchosts[self.x.xbmcactive][0], username=self.x.xbmchosts[self.x.xbmcactive][1], password=self.x.xbmchosts[self.x.xbmcactive][2], port=self.x.xbmchosts[self.x.xbmcactive][3], ) self.x.xbmcactive = saveactive self.x.xbmchosts = savehosts print "xbmc connected!!" except Exception, e: for i in e: msg = "xbmc Exception: %s" % e self.replyMessage(user, msg) return if action == "play" or action == "pause": result = self.x.play_pause() if result: msg = "Toggling play/pause on " + self.x.xbmchosts[self.x.xbmcactive][4] self.replyMessage(user, msg)