def __init__(self,name,address,port): self.name = name self.address = address self.port = port #figure out what kind of comms for this host hostname = socket.gethostname() host_address = '' try: host_address = socket.gethostbyname(hostname) except: #do nothing here, we'll just use a blank string pass if(self.address == '127.0.0.1' or self.address == hostname or self.address == host_address): #we have a 'local' host self.jsonComm = LocalComms() else: self.jsonComm = RemoteComms(self.address,self.port)
def __init__(self, name, address, port, user, password): self.name = name self.address = address self.port = port self.user = user self.password = password #figure out what kind of comms for this host hostname = socket.gethostname() host_address = '' try: host_address = socket.gethostbyname(hostname) except: #do nothing here, we'll just use a blank string pass if (self.address == '127.0.0.1' or self.address == hostname or self.address == host_address): #we have a 'local' host self.jsonComm = LocalComms() else: self.jsonComm = RemoteComms(self.address, self.port, self.user, self.password)
class XbmcHost: name = '' address = '' port = 80 jsonComm = None def __init__(self,name,address,port): self.name = name self.address = address self.port = port #figure out what kind of comms for this host hostname = socket.gethostname() host_address = '' try: host_address = socket.gethostbyname(hostname) except: #do nothing here, we'll just use a blank string pass if(self.address == '127.0.0.1' or self.address == hostname or self.address == host_address): #we have a 'local' host self.jsonComm = LocalComms() else: self.jsonComm = RemoteComms(self.address,self.port) def executeJSON(self,query,params): if(self.jsonComm != None): return self.jsonComm.executeJSON(query,params) else: return None def isPlaying(self): return self._getPlayerId() def getPlaylist(self,playerid = None): result = {} if(playerid == None): playerid = self._getPlayerId() if(playerid >= 0): items = self.executeJSON("Playlist.GetItems",'{"playlistid":' + str(playerid) + ',"properties":["file","title"]}') result = items['items'] return result def playingProperties(self,playerid=None): result = {} if(playerid == None): playerid = self._getPlayerId() if(playerid >= 0): result = self.executeJSON("Player.GetProperties",'{"playerid":' + str(playerid) + ', "properties":["percentage","position","speed"]}') return result def addItems(self,items,playerid): #first clear the current playlist self.executeJSON('Playlist.Clear','{"playlistid": ' + str(playerid) + '}') for aFile in items: self.executeJSON('Playlist.Add','{"playlistid":' + str(playerid) + ',"item": {"file": "' + aFile['file'] + '" } }') def playPosition(self,position,playerid): #play the item at a given position in the playlist self.executeJSON("Player.Open",'{"item": { "playlistid": ' + str(playerid) + ',"position":' + str(position) + ' } }') def playFile(self,aFile,resume=0): #play a specific file, resume if sent self.executeJSON("Player.Open",'{"item": {"file":"' + aFile + '"},"options":{"resume":' + str(resume) + '}}') def seekFile(self,percent,playerid=None): if(playerid == None): playerid = self._getPlayerId() #seek to this point in the file self.executeJSON("Player.Seek",'{"playerid":' + str(playerid) + ', "value":' + str(percent) + '}') def stop(self,playerid=None): if(playerid == None): playerid = self._getPlayerId() #stop the player self.executeJSON('Player.Stop','{"playerid":' + str(playerid) + '}') def sendNotification(self,message): self.executeJSON('GUI.ShowNotification','{"title":"' + utils.getSetting("notification_title") + '","message":"' + message + '"}') def _getPlayerId(self): utils.log("Finding playerid") #check if this player is actively playing something check_playing = self.executeJSON('Player.GetActivePlayers','{}') if(check_playing != None): if(len(check_playing) > 0): return check_playing[0]['playerid'] else: return -1 else: return -2
class XbmcHost: name = '' address = '' port = 80 user = '' password = '' jsonComm = None def __init__(self, name, address, port, user, password): self.name = name self.address = address self.port = port self.user = user self.password = password #figure out what kind of comms for this host hostname = socket.gethostname() host_address = '' try: host_address = socket.gethostbyname(hostname) except: #do nothing here, we'll just use a blank string pass if (self.address == '127.0.0.1' or self.address == hostname or self.address == host_address): #we have a 'local' host self.jsonComm = LocalComms() else: self.jsonComm = RemoteComms(self.address, self.port, self.user, self.password) def executeJSON(self, query, params): if (self.jsonComm != None): return self.jsonComm.executeJSON(query, params) else: return None def isPlaying(self): return self._getPlayerId() def getPlaylist(self, playerid=None): result = [] if (playerid == None): playerid = self._getPlayerId() if (playerid >= 0): if (playerid == 1): #playing video only one item items = self.executeJSON( "Player.GetItem", '{"playerid":' + str(playerid) + ',"properties":["file","title"]}') result.append(items['item']) else: items = self.executeJSON( "Playlist.GetItems", '{"playlistid":' + str(playerid) + ',"properties":["file","title"]}') result = items['items'] return result def playingProperties(self, playerid=None): result = {} if (playerid == None): playerid = self._getPlayerId() if (playerid >= 0): result = self.executeJSON( "Player.GetProperties", '{"playerid":' + str(playerid) + ', "properties":["percentage","position","speed"]}') return result def addItems(self, items, playerid): #first clear the current playlist self.executeJSON('Playlist.Clear', '{"playlistid": ' + str(playerid) + '}') for aFile in items: self.executeJSON( 'Playlist.Add', '{"playlistid":' + str(playerid) + ',"item": {"file": "' + aFile['file'] + '" } }') def playPosition(self, position, playerid): #play the item at a given position in the playlist self.executeJSON( "Player.Open", '{"item": { "playlistid": ' + str(playerid) + ',"position":' + str(position) + ' } }') def playFile(self, aFile, resume=0): #play a specific file, resume if sent self.executeJSON( "Player.Open", '{"item": {"file":"' + aFile + '"},"options":{"resume":' + str(resume) + '}}') def seekFile(self, percent, playerid=None): if (playerid == None): playerid = self._getPlayerId() #seek to this point in the file self.executeJSON( "Player.Seek", '{"playerid":' + str(playerid) + ', "value":' + str(percent) + '}') def stop(self, playerid=None): if (playerid == None): playerid = self._getPlayerId() #stop the player self.executeJSON('Player.Stop', '{"playerid":' + str(playerid) + '}') def sendNotification(self, message): self.executeJSON( 'GUI.ShowNotification', '{"title":"' + utils.getSetting("notification_title") + '","message":"' + message + '"}') def _getPlayerId(self): utils.log("Finding playerid") #check if this player is actively playing something check_playing = self.executeJSON('Player.GetActivePlayers', '{}') if (check_playing != None): if (len(check_playing) > 0): return check_playing[0]['playerid'] else: return -1 else: return -2