All pastes #1352147 Raw Edit

Untitled

public python v1 · immutable
#1352147 ·published 2009-03-03 19:48 UTC
rendered paste body
version = "0.3"__module_name__ = "XBMC Announcer"__module_version__ = version__module_description__ = "announces XBMC now playing"import sys,string,urllib,xchat#xboxIP      = "192.168.1.250"    # change this to your xbox's IPxboxIP      = "127.0.0.1:8080"    # change this to your xbox's IPdef makeHttpRequest(command):   try:     u = urllib.urlopen('http://'+xboxIP+'/xbmcCmds/xbmcHttp?command='+command)   except IOError, err:      print "  ERROR: Xbox isn't online", err      return 0   else:      u=u.readlines()      line = u[0].lower()      if line.count("error") > 0:         print "server error"         return 0      elif line.count("html") > 0:         line = u[1].lower()         if line.count("error") > 0:            print "xbmc httpapi error"            return 0         elif line.count("ok") > 0:#             print "OK"            return 1         elif line.count("[nothing playing]") > 0:            print " XBMC isn't playing anything"            return 0         else:            return udef xbmcNP(word,wordeol,userdata):   data  = {}   response=makeHttpRequest("getcurrentlyplaying")   if response != 0:      for i in response:         try:            key, val = i.strip().replace('<li>','').replace('</html>','').split(':',1)         except:            continue         key   = key.lower().strip()         val   = val.strip()         if key == "time" or key == "duration":            try:               val = val.split(':')               val[0] = int(val[0])               val = '%d:%s' % (val[0], val[1])            except:               pass         data[key] = val      prog = float(data['percentage'])/100      progbar = []      progbar.append('8')      for i in range(int(8*prog)):         progbar.append('=')      progbar.append('D')      for i in range(8-int(8*prog)):         progbar.append('~')      data['progbar'] = str(progbar).replace("['",'').replace("', '", '').replace("']",'')      if data["type"] == "Audio":         xchat.command('msg %s XBMCnp: %s "%s - %s" (%s) [%s%%|%s|%s|%skbps]' % (xchat.get_info('channel'), data["type"], data["artist"], data["title"], data["album"], data["percentage"], data["progbar"], data["duration"], "?")) #data["bitrate"]))      elif data["type"] == "Video":         xchat.command('msg %s XBMCnp: %s "%s" (%s) [%s%%|%s|%s|%s]' % (xchat.get_info('channel'), data["type"], data["title"], data["year"], data["percentage"], data["progbar"], data["duration"], data["rating"]))      return xchat.EAT_ALLdef xbmcPrev(word,wordeol,userdata):   response=makeHttpRequest("playprev")   if response:      xchat.prnt(" playing previous track")   else:      xchat.prnt("  ERROR: play previous failed")   return xchat.EAT_ALLdef xbmcNext(word,wordeol,userdata):   response=makeHttpRequest("playnext")   if response:      xchat.prnt(" playing next track")   else:      xchat.prnt("  ERROR: play next failed")   return xchat.EAT_ALLxchat.hook_command('xbmcnp',xbmcNP)xchat.hook_command('xbmcnext',xbmcNext)xchat.hook_command('xbmcprev',xbmcPrev)xchat.prnt("XBMC Announcer v%s Loaded!" % (version))