def executeKodiCmd(self, message): if self.kodiCmds and 'title' in message: match = self.re_kodiCmd.match(message['title']) if match: cmd = match.group('cmd') if cmd in self.kodiCmds: try: cmdObj = self.kodiCmds[cmd] jsonrpc = cmdObj['JSONRPC'] if 'body' in message and len(message['body']) > 0: params = message['body'].split('||') # escape bracket '{}' => '{{}}' jsonrpc = jsonrpc.replace('{', '{{').replace('}', '}}') # sobstitute custom placeholder '<$var>' => '{var}' jsonrpc = self.re_kodiCmdPlaceholder.sub( '{\\1}', jsonrpc) # format with passed params jsonrpc = jsonrpc.format(params=params) common.log('Executing cmd "%s": %s' % (cmd, jsonrpc)) result = common.executeJSONRPC(jsonrpc) common.log('Result for cmd "%s": %s' % (cmd, result)) title = common.localise(30104) % cmd body = '' if 'notification' in cmdObj: # same transformation as jsonrpc var body = cmdObj['notification'].replace( '{', '{{').replace('}', '}}') body = self.re_kodiCmdPlaceholder.sub( '{\\1}', body) body = body.format(result=result) except Exception as ex: title = 'ERROR: ' + common.localise(30104) % cmd body = ' '.join(str(arg) for arg in ex.args) common.log(body, xbmc.LOGERROR) common.traceError() common.showNotification(title, body, self.notificationTime, self.kodiCmdsNotificationIcon) return True else: common.log('No "%s" cmd founded!' % cmd, xbmc.LOGERROR) return False
def executeKodiCmd(self, message): if self.kodiCmds and 'title' in message: match = self.re_kodiCmd.match(message['title']) if match: cmd = match.group('cmd') if cmd in self.kodiCmds: try: cmdObj = self.kodiCmds[cmd] jsonrpc = cmdObj['JSONRPC'] if 'body' in message and len(message['body']) > 0: params = message['body'].split('||') # escape bracket '{}' => '{{}}' jsonrpc = jsonrpc.replace('{', '{{').replace('}', '}}') # sobstitute custom placeholder '<$var>' => '{var}' jsonrpc = self.re_kodiCmdPlaceholder.sub('{\\1}', jsonrpc) # format with passed params jsonrpc = jsonrpc.format(params=params) common.log('Executing cmd "%s": %s' % (cmd, jsonrpc)) result = common.executeJSONRPC(jsonrpc) common.log('Result for cmd "%s": %s' % (cmd, result)) title = common.localise(30104) % cmd body = '' if 'notification' in cmdObj: # same transformation as jsonrpc var body = cmdObj['notification'].replace('{', '{{').replace('}', '}}') body = self.re_kodiCmdPlaceholder.sub('{\\1}', body) body = body.format(result=result) except Exception as ex: title = 'ERROR: ' + common.localise(30104) % cmd body = ' '.join(str(arg) for arg in ex.args) common.log(body, xbmc.LOGERROR) common.traceError() common.showNotification(title, body, self.notificationTime, self.kodiCmdsNotificationIcon) return True else: common.log('No "%s" cmd founded!' % cmd, xbmc.LOGERROR) return False
def _onKodiNotification(self, sender, method, data): import json data = json.loads(data) if sender == 'xbmc': if method == 'Player.OnPlay' and self.stg_pbMirroringOutMediaNfo: common.log('onKodiNotification: %s %s %s' % (sender, method, data)) title = body = icon = None playerId = data['player']['playerid'] if playerId < 0: result = data else: result = common.executeJSONRPC('{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title","year","tagline","album","artist","plot","episode","season","showtitle","channel","channeltype","channelnumber","thumbnail","file"], "playerid": ' + str(playerId) + ' }, "id": "1"}') if 'item' in result: if data['item']['type'] == 'movie': if 'title' in result['item'] and result['item']['title'] != '': title = '%s (%s)' % (result['item']['title'], result['item'].get('year','')) body = result['item'].get('tagline',xbmc.getInfoLabel('VideoPlayer.Tagline')) elif data['item']['type'] == 'song' or data['item']['type'] == 'musicvideo': if 'title' in result['item'] and result['item']['title'] != '': title = result['item']['title'] body = '%s / %s' % (result['item']['album'], ', '.join(result['item']['artist'])) elif data['item']['type'] == 'picture': title = 'Picture' body = data['item']['file'] elif data['item']['type'] == 'episode': title = result['item']['title'] body = '%s %sx%s' % (result['item']['showtitle'], result['item']['episode'], result['item']['season']) elif data['item']['type'] == 'channel': title = result['item']['title'] body = '%s - %s (%s)' % (result['item']['channelnumber'], result['item']['channel'], result['item']['channeltype'], ) else: title = result['item']['label'] if 'label' in result['item'] else result['item']['file'] body = None thumbnailFilePath = None if 'thumbnail' in result['item']: thumbnailFilePath = result['item']['thumbnail'] else: thumbnailFilePath = xbmc.getInfoLabel('Player.Art(thumb)') if thumbnailFilePath: try: icon = common.fileTobase64(thumbnailFilePath, imgFormat='JPEG', imgSize=(72, 72)) if not icon: raise Exception('No Icon') except: icon = self.xbmcImgEncoded else: title = 'unknown' body = None icon = self.xbmcImgEncoded ephemeralMsg = {'title': title, 'body': body, 'notification_id': self.pbPlaybackNotificationId, 'icon': icon} if len(self.pushbullet.sendEphemeral(ephemeralMsg)) == 0: common.log(u'Ephemeral push sended: {0} - {1}'.format(ephemeralMsg['title'], ephemeralMsg['body'])) else: common.log(u'Ephemeral push NOT send: {0} - {1}'.format(ephemeralMsg['title'], ephemeralMsg['body']), xbmc.LOGERROR) elif method == 'Player.OnStop' and self.stg_pbMirroringOutMediaNfo: common.log('onKodiNotification: %s %s %s' % (sender, method, data)) ephemeralDimiss = {'notification_id': self.pbPlaybackNotificationId} if len(self.pushbullet.dismissEphemeral(ephemeralDimiss)) == 0: common.log('Ephemeral dismiss send') else: common.log('Ephemeral dismiss NOT send', xbmc.LOGERROR)
def _onKodiNotification(self, sender, method, data): import json data = json.loads(data) if sender == 'xbmc': if method == 'Player.OnPlay' and self.stg_pbMirroringOutMediaNfo: common.log('onKodiNotification: %s %s %s' % (sender, method, data)) title = body = icon = None playerId = data['player']['playerid'] if playerId < 0: result = data else: result = common.executeJSONRPC( '{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title","year","tagline","album","artist","plot","episode","season","showtitle","channel","channeltype","channelnumber","thumbnail","file"], "playerid": ' + str(playerId) + ' }, "id": "1"}') if 'item' in result: if data['item']['type'] == 'movie': if 'title' in result[ 'item'] and result['item']['title'] != '': title = '%s (%s)' % (result['item']['title'], result['item'].get( 'year', '')) body = result['item'].get( 'tagline', xbmc.getInfoLabel('VideoPlayer.Tagline')) elif data['item']['type'] == 'song' or data['item'][ 'type'] == 'musicvideo': if 'title' in result[ 'item'] and result['item']['title'] != '': title = result['item']['title'] body = '%s / %s' % (result['item']['album'], ', '.join( result['item']['artist'])) elif data['item']['type'] == 'picture': title = 'Picture' body = data['item']['file'] elif data['item']['type'] == 'episode': title = result['item']['title'] body = '%s %sx%s' % (result['item']['showtitle'], result['item']['episode'], result['item']['season']) elif data['item']['type'] == 'channel': title = result['item']['title'] body = '%s - %s (%s)' % ( result['item']['channelnumber'], result['item']['channel'], result['item']['channeltype'], ) else: title = result['item']['label'] if 'label' in result[ 'item'] else result['item']['file'] body = None thumbnailFilePath = None if 'thumbnail' in result['item']: thumbnailFilePath = result['item']['thumbnail'] else: thumbnailFilePath = xbmc.getInfoLabel( 'Player.Art(thumb)') if thumbnailFilePath: try: icon = common.fileTobase64(thumbnailFilePath, imgFormat='JPEG', imgSize=(72, 72)) if not icon: raise Exception('No Icon') except: icon = self.xbmcImgEncoded else: title = 'unknown' body = None icon = self.xbmcImgEncoded ephemeralMsg = { 'title': title, 'body': body, 'notification_id': self.pbPlaybackNotificationId, 'icon': icon } if len(self.pushbullet.sendEphemeral(ephemeralMsg)) == 0: common.log(u'Ephemeral push sended: {0} - {1}'.format( ephemeralMsg['title'], ephemeralMsg['body'])) else: common.log( u'Ephemeral push NOT send: {0} - {1}'.format( ephemeralMsg['title'], ephemeralMsg['body']), xbmc.LOGERROR) elif method == 'Player.OnStop' and self.stg_pbMirroringOutMediaNfo: common.log('onKodiNotification: %s %s %s' % (sender, method, data)) ephemeralDimiss = { 'notification_id': self.pbPlaybackNotificationId } if len(self.pushbullet.dismissEphemeral(ephemeralDimiss)) == 0: common.log('Ephemeral dismiss send') else: common.log('Ephemeral dismiss NOT send', xbmc.LOGERROR)