Advertisement
Guest User

Untitled

a guest
Aug 10th, 2010
1,355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.32 KB | None | 0 0
  1. import urllib, urllib2
  2. import base64
  3. import re
  4.  
  5.  
  6. ##XBMC Host Info##
  7.  
  8. host = ""
  9. username = ''
  10. password = ''
  11.  
  12. #####
  13.  
  14. event = eg.event.suffix
  15. parts = event.split("::")
  16.  
  17.  
  18. #########Incoming Call Handling##########
  19.  
  20. if parts[2] == "CallAccept":
  21.     baseUrl = "http://" + host + "/xbmcCmds/xbmcHttp?command="
  22.     cmd = "getcurrentlyplaying"
  23.  
  24.     url = baseUrl + cmd
  25.  
  26.     req = urllib2.Request(url)
  27.     if password != '':
  28.       base64string = base64.encodestring('%s:%s' % (username, password))[:-1]
  29.       authheader =  "Basic %s" % base64string
  30.       req.add_header("Authorization", authheader)
  31.     handle = urllib2.urlopen(req, timeout=10)
  32.     text = handle.read()
  33.     handle.close()
  34.  
  35.     text = re.sub(r'<[^>]*?>', '', text)
  36.  
  37.     if text.find("Type:Video") != -1 and text.find("PlayStatus:Playing") != -1:
  38.         print "Pause XBMC Video"
  39.         eg.plugins.XBMC.Pause()
  40.        
  41.     if text.find("Type:Audio") != -1 and text.find("PlayStatus:Playing") != -1:
  42.         print "Lower Volume"
  43.         eg.plugins.System.SetMasterVolume(18.0, 0)
  44.  
  45. #########Call End Handling##########
  46.  
  47. if parts[2] == "CallEnd":
  48.     baseUrl = "http://" + host + "/xbmcCmds/xbmcHttp?command="
  49.     cmd = "getcurrentlyplaying"
  50.  
  51.     url = baseUrl + cmd
  52.  
  53.     req = urllib2.Request(url)
  54.     if password != '':
  55.       base64string = base64.encodestring('%s:%s' % (username, password))[:-1]
  56.       authheader =  "Basic %s" % base64string
  57.       req.add_header("Authorization", authheader)
  58.     handle = urllib2.urlopen(req, timeout=10)
  59.     text = handle.read()
  60.     handle.close()
  61.  
  62.     text = re.sub(r'<[^>]*?>', '', text)
  63.  
  64.     if text.find("Type:Video") != -1 and text.find("PlayStatus:Paused") != -1:
  65.         print "Resume XBMC Video"
  66.         eg.plugins.XBMC.Play()
  67.        
  68.     if text.find("Type:Audio") != -1 and text.find("PlayStatus:Playing") != -1:
  69.         print "Raise Volume"
  70.         eg.plugins.System.SetMasterVolume(100.0, 0)
  71.        
  72. #########CallDialed Handling##########
  73.  
  74. if parts[2] == "CallDialed":
  75.     baseUrl = "http://" + host + "/xbmcCmds/xbmcHttp?command="
  76.     cmd = "getcurrentlyplaying"
  77.  
  78.     url = baseUrl + cmd
  79.  
  80.     req = urllib2.Request(url)
  81.     if password != '':
  82.       base64string = base64.encodestring('%s:%s' % (username, password))[:-1]
  83.       authheader =  "Basic %s" % base64string
  84.       req.add_header("Authorization", authheader)
  85.     handle = urllib2.urlopen(req, timeout=10)
  86.     text = handle.read()
  87.     handle.close()
  88.  
  89.     text = re.sub(r'<[^>]*?>', '', text)
  90.  
  91.     if text.find("Type:Video") != -1 and text.find("PlayStatus:Playing") != -1:
  92.         print "Pause XBMC Video"
  93.         eg.plugins.XBMC.Pause()
  94.        
  95.     if text.find("Type:Audio") != -1 and text.find("PlayStatus:Playing") != -1:
  96.         print "Lower Volume"
  97.         eg.plugins.System.SetMasterVolume(18.0, 0)
  98.        
  99. #########SMS Handling#########
  100.  
  101. if parts[2] == "SMS":
  102.     if parts[3] == "REPLACE THIS TEXT WITH CONTACT NAME":
  103.        if parts[4] == "Xbmc":
  104.         eg.plugins.System.Execute(u'C:\\Program Files (x86)\\XBMC\\XBMC.exe', u'', 0, False, 2, u'')
  105.     if parts[3] == "REPLACE THIS TEXT WITH CONTACT NAME":
  106.        if parts[4] == "Hibernate":
  107.         eg.plugins.System.Hibernate(True)
  108.     if parts[3] == "REPLACE THIS TEXT WITH CONTACT NAME":
  109.        if parts[4] == "PC Off":
  110.         eg.plugins.System.PowerDown(True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement