Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # addon.py
- import xbmc
- import xbmcgui
- import xbmcaddon
- import sys
- import socket
- import select
- import time
- #import random
- import threading
- import Queue
- xbmc.executebuiltin('Skin.SetString(seekdown,False)')
- xbmc.executebuiltin('Skin.SetString(seekup,False)')
- host = "192.168.47.140"
- port = 7844
- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- s.connect((host, port))
- s.settimeout(300)
- q = Queue.Queue()
- def receiver() : # Thread T
- while True :
- data = s.recv(1000)
- q.put(data)
- if not data :
- print '\n\tDisconnected from Radio Server!\n'
- sys.exit()
- else :
- formatData(q)
- time.sleep(.01)
- print '\n\t KODI says that AbortRequested is: ' + str(xbmc.abortRequested)
- def sender(command) :
- command = command + '\n'
- print 'Sending command: ' + command
- s.send(command)
- def myui() : # Thread M
- rCurr = 'True'
- while True :
- #while(not xbmc.abortRequested):
- skUP = xbmc.getInfoLabel('Skin.String(seekup)')
- skDN = xbmc.getInfoLabel('Skin.String(seekdown)')
- tnUP = xbmc.getInfoLabel('Skin.String(tuneup)')
- tnDN = xbmc.getInfoLabel('Skin.String(tunedown)')
- rACT = xbmc.getInfoLabel('Skin.String(RadioActive)')
- if 'True' in skUP :
- #print '\t Seek UP Requested'
- xbmc.executebuiltin('Skin.SetString(seekup,False)')
- sender('seekup')
- time.sleep(.1)
- elif 'True' in skDN :
- #print '\t Seek DOWN Requested'
- xbmc.executebuiltin('Skin.SetString(seekdown,False)')
- sender('seekdown')
- time.sleep(.1)
- elif 'True' in tnUP :
- #print '\t Seek UP Requested'
- xbmc.executebuiltin('Skin.SetString(tuneup,False)')
- sender('tuneup')
- time.sleep(.1)
- elif 'True' in tnDN :
- #print '\t Seek DOWN Requested'
- xbmc.executebuiltin('Skin.SetString(tunedown,False)')
- sender('tunedown')
- time.sleep(.1)
- if rACT == rCurr :
- # Do Nothing
- time.sleep(.1)
- pass
- elif 'True' in rACT :
- sender('muteoff')
- rCurr = 'True'
- time.sleep(.01)
- elif 'False' in rACT :
- sender('muteon')
- rCurr = 'False'
- time.sleep(.01)
- else :
- time.sleep(.1)
- pass
- def formatData(q) :
- while not q.empty() :
- data = q.get()
- if data.count('|') != 2 :
- return
- elif data.count('|') == 2 :
- data = data.replace('|','')
- cmd, val = data.split(':',1)
- val = val.replace(':',' ')
- val = val.replace(' ','')
- val = val.replace('\n','')
- if 'seek' in cmd :
- mpt = ''
- xbmcgui.Window(10000).setProperty('Tune', val)
- xbmcgui.Window(10000).setProperty('HDArtist', mpt)
- xbmcgui.Window(10000).setProperty('HDArtist2', mpt)
- xbmcgui.Window(10000).setProperty('HDTitle', mpt)
- xbmcgui.Window(10000).setProperty('HDTitle2', mpt)
- xbmcgui.Window(10000).setProperty('HDCallsign', mpt)
- xbmcgui.Window(10000).setProperty('HDStreamlock', 'False')
- xbmcgui.Window(10000).setProperty('HDActive', 'False')
- elif 'hd' in cmd :
- if 'artist' in cmd :
- if '1' in val[0]:
- val = val.replace('1 ','',1) # <~~ Does this work?
- xbmcgui.Window(10000).setProperty('HDArtist', val)
- #print 'HD Artist (1) ' + val
- if '2' in val[0]:
- val = val.replace('2 ','',1)
- xbmcgui.Window(10000).setProperty('HDArtist2', val)
- #print 'HD Artist (2) ' + val
- elif 'title' in cmd :
- if '1' in val[0]:
- val = val.replace('1 ','',1)
- xbmcgui.Window(10000).setProperty('HDTitle', val)
- #print 'HD Title (1) ' + val
- if '2' in val[0]:
- val = val.replace('2 ','',1)
- xbmcgui.Window(10000).setProperty('HDTitle2', val)
- #print 'HD Title (2) ' + val
- elif 'call' in cmd :
- xbmcgui.Window(10000).setProperty('HDCallsign', val)
- #print 'HD Callsign ' + val
- elif 'active' in cmd :
- if 'false' in val:
- xbmcgui.Window(10000).setProperty('HDActive', 'False')
- #pass
- if 'true' in val:
- xbmcgui.Window(10000).setProperty('HDActive', 'True')
- #print 'HD Active'
- #pass
- elif 'streamlock' in cmd:
- if 'false' in val :
- xbmcgui.Window(10000).setProperty('HDStreamlock', 'False')
- #print 'No stream lock'
- #pass
- if 'true' in val :
- xbmcgui.Window(10000).setProperty('HDStreamlock', 'True')
- #print 'Stream locked'
- #pass
- elif 'subchannel' in cmd :
- if val < '0':
- xbmcgui.Window(10000).setProperty('HDSubs', val)
- #print val + ' subchannels available'
- #pass
- else :
- #print 'Else! ' + val
- pass
- elif 'rds' in cmd:
- if 'enable' in cmd :
- #print 'RDS Enabled'
- xbmcgui.Window(10000).setProperty('HDArtist2', 'RDS')
- #pass
- elif 'service' in cmd :
- #print 'T.0 ' + val
- xbmcgui.Window(10000).setProperty('HDArtist', val)
- #pass
- elif 'text' in cmd :
- xbmcgui.Window(10000).setProperty('HDTitle', val)
- #print 'T.1 ' + val
- #pass
- elif 'genre' in cmd:
- xbmcgui.Window(10000).setProperty('HDTitle2', val)
- #print 'Genre ' + val
- #pass
- elif 'tune' in cmd :
- val = val.replace('FM ','',1)
- xbmcgui.Window(10000).setProperty('Tune', val)
- #print '\tStation: ' + val
- time.sleep(.001)
- t = threading.Thread(name='receiver', target=receiver)
- t.setDaemon(True)
- t.start()
- m = threading.Thread(name='myui', target=myui)
- m.setDaemon(True)
- m.start()
- sender('tune 1027 fm')
- sender('volume 100')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement