Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.36 KB | None | 0 0
  1. # addon.py
  2. import xbmc
  3. import xbmcgui
  4. import xbmcaddon
  5. import sys
  6. import socket
  7. import select
  8. import time
  9. from multiprocessing import Process, Queue
  10.  
  11. xbmc.executebuiltin('Skin.SetString(seekdown,False)')
  12. xbmc.executebuiltin('Skin.SetString(seekup,False)')
  13.  
  14. host = "192.168.47.140"
  15. port = 7844
  16. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  17. s.connect((host, port))
  18. s.settimeout(300)
  19. q = Queue()
  20. monitor = xbmc.Monitor()
  21. live = True
  22.  
  23. def receiver() : # Process T
  24.     xbmc.log("RadioHD receiver process started %s" % time.time(), level=xbmc.LOGNOTICE)
  25.     while True :
  26.         data = s.recv(1000)
  27.         q.put(data)
  28.         if not data :
  29.             xbmc.log('[script.radioHD] Disconnected from radio server! Bailing...')
  30.             sys.exit()
  31.         else :
  32.             formatData(q)
  33.             time.sleep(.001)
  34.            
  35.            
  36.        
  37. def sender(command) :
  38.     command = command + '\n'
  39.     print 'Sending command: ' + command
  40.     s.send(command)
  41.  
  42. def myui() : # Process M
  43.     rCurr = 'True'
  44.     xbmc.log("RadioHD myui process started %s" % time.time(), level=xbmc.LOGNOTICE)
  45.    
  46.     while True :
  47.         skUP = xbmc.getInfoLabel('Skin.String(seekup)')
  48.         skDN = xbmc.getInfoLabel('Skin.String(seekdown)')
  49.         tnUP = xbmc.getInfoLabel('Skin.String(tuneup)')
  50.         tnDN = xbmc.getInfoLabel('Skin.String(tunedown)')
  51.         rACT = xbmc.getInfoLabel('Skin.String(RadioActive)')
  52.         if 'True' in skUP :
  53.             #print '\t Seek UP Requested'
  54.             xbmc.executebuiltin('Skin.SetString(seekup,False)')
  55.             sender('seekup')
  56.             time.sleep(.01)
  57.         elif 'True' in skDN :
  58.             #print '\t Seek DOWN Requested'
  59.             xbmc.executebuiltin('Skin.SetString(seekdown,False)')  
  60.             sender('seekdown')
  61.             time.sleep(.01)    
  62.         elif 'True' in tnUP :
  63.             #print '\t Tune UP Requested'
  64.             xbmc.executebuiltin('Skin.SetString(tuneup,False)')
  65.             sender('tuneup')
  66.             time.sleep(.01)
  67.         elif 'True' in tnDN :
  68.             #print '\t Tune DOWN Requested'
  69.             xbmc.executebuiltin('Skin.SetString(tunedown,False)')  
  70.             sender('tunedown')
  71.             time.sleep(.01)
  72.         if rACT == rCurr :
  73.             # Do Nothing
  74.             time.sleep(.01)
  75.             pass
  76.         elif 'True' in rACT :
  77.                 sender('muteoff')
  78.                 rCurr = 'True'
  79.                 time.sleep(.01)
  80.         elif 'False' in rACT :
  81.                 sender('muteon')
  82.                 rCurr = 'False'
  83.                 time.sleep(.01)
  84.         else :
  85.             time.sleep(.01)
  86.             pass
  87.        
  88. def formatData(q) :
  89.     while not q.empty() :
  90.         data = q.get()
  91.         if data.count('|') != 2 :
  92.             return
  93.         elif data.count('|') == 2 :
  94.             data = data.replace('|','')
  95.             cmd, val = data.split(':',1)
  96.             val = val.replace(':',' ')
  97.             val = val.replace('  ','')
  98.             val = val.replace('\n','')
  99.             if 'seek' in cmd :
  100.                 mpt = ''
  101.                 xbmcgui.Window(10000).setProperty('Tune', val)
  102.                 xbmcgui.Window(10000).setProperty('HDArtist', mpt)
  103.                 xbmcgui.Window(10000).setProperty('HDArtist2', mpt)
  104.                 xbmcgui.Window(10000).setProperty('HDTitle', mpt)
  105.                 xbmcgui.Window(10000).setProperty('HDTitle2', mpt)
  106.                 xbmcgui.Window(10000).setProperty('HDCallsign', mpt)
  107.                 xbmcgui.Window(10000).setProperty('HDStreamlock', 'False')             
  108.                 xbmcgui.Window(10000).setProperty('HDActive', 'False') 
  109.                 xbmcgui.Window(10000).setProperty('HDSubs', mpt)               
  110.             elif 'hd' in cmd :
  111.                 if 'artist' in cmd :
  112.                     if '1' in val[0]:
  113.                         val = val.replace('1 ','',1)
  114.                         xbmcgui.Window(10000).setProperty('HDArtist', val)
  115.                     if '2' in val[0]:
  116.                         val = val.replace('2 ','',1)
  117.                         xbmcgui.Window(10000).setProperty('HDArtist2', val)
  118.                 elif 'title' in cmd :
  119.                     if '1' in val[0]:
  120.                         val = val.replace('1 ','',1)
  121.                         xbmcgui.Window(10000).setProperty('HDTitle', val)
  122.                     if '2' in val[0]:
  123.                         val = val.replace('2 ','',1)
  124.                         xbmcgui.Window(10000).setProperty('HDTitle2', val)
  125.                 elif 'call' in cmd :
  126.                     xbmcgui.Window(10000).setProperty('HDCallsign', val)
  127.                 elif 'active' in cmd :
  128.                     if 'false' in val:
  129.                         xbmcgui.Window(10000).setProperty('HDActive', 'False')
  130.                     if 'true' in val:
  131.                         xbmcgui.Window(10000).setProperty('HDActive', 'True')
  132.                 elif 'streamlock' in cmd:
  133.                     if 'false' in val :
  134.                         xbmcgui.Window(10000).setProperty('HDStreamlock', 'False')
  135.                     if 'true' in val :
  136.                         xbmcgui.Window(10000).setProperty('HDStreamlock', 'True')
  137.                 elif 'subchannel' in cmd :
  138.                     if val < '0':
  139.                         xbmcgui.Window(10000).setProperty('HDSubs', val)
  140.                 else :
  141.                     pass
  142.                    
  143.             elif 'rds' in cmd:
  144.                 if 'enable' in cmd :
  145.                     xbmcgui.Window(10000).setProperty('HDArtist2', 'RDS')  
  146.                 elif 'service' in cmd :
  147.                     xbmcgui.Window(10000).setProperty('HDArtist', val)
  148.                 elif 'text' in cmd :
  149.                     xbmcgui.Window(10000).setProperty('HDTitle', val)
  150.                 elif 'genre' in cmd:
  151.                     xbmcgui.Window(10000).setProperty('HDTitle2', val) 
  152.  
  153.                
  154.             elif 'tune' in cmd :
  155.                 val = val.replace('FM ','',1)
  156.                 xbmcgui.Window(10000).setProperty('Tune', val)
  157.                 #print '\tStation: ' + val
  158.         time.sleep(.001)
  159.        
  160. if __name__ == '__main__':
  161.     t = Process(target=receiver)
  162.     t.daemon = True
  163.  
  164.     xbmc.log("RadioHD Rx process starting %s" % time.time(), level=xbmc.LOGNOTICE)
  165.     t.start()
  166.  
  167.     m = Process(target=myui)
  168.     m.daemon = True
  169.  
  170.     xbmc.log("RadioHD myui process starting %s" % time.time(), level=xbmc.LOGNOTICE)
  171.     m.start()
  172.  
  173.     sender('tune 1027 fm')
  174.     sender('volume 100')
  175.     sender('bass 10')
  176.     sender('treble 10')
  177.  
  178.  
  179.  
  180.     while not monitor.abortRequested():
  181.         if monitor.waitForAbort(1) :
  182.             xbmc.log("**************RadioHD*********************", level=xbmc.LOGNOTICE)
  183.             xbmc.log("\tRadioHD %s" % time.time(), level=xbmc.LOGNOTICE)
  184.             t.terminate()
  185.             m.terminate()
  186.             break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement