def showNotificationFromMessage(self,message): title = message.get('title',message.get('name',message.get('file_name',''))) or message.get('url','').rsplit('/',1)[-1] body = message.get('body',message.get('address','')).replace("\n", " / ") if not body and message['type'] == 'list': body = '{0} items'.format(len(message.get('items',[]))) common.showNotification(title, body, self.notificationTime, self.notificationIcon)
def _onMirrorPush(self, message): if 'icon' in message: # BUILD KODI NOTIFICATION applicationNameMirrored = message.get('application_name', '') titleMirrored = message.get('title', '') # Add Title... title = applicationNameMirrored if not titleMirrored else applicationNameMirrored + ': ' title += titleMirrored # ...Body... body = message.get('body', '').rstrip('\n').replace('\n', ' / ') # ...and Icon iconPath = common.base64ToFile(message['icon'], self.imgFilePath, imgFormat='JPEG', imgSize=(96, 96)) common.showNotification(title, body, self.notificationTime, iconPath) # Action on phone call # Works only with com.android.dialer (Android stock dialer) if self.cmdOnPhoneCallPush != 'none' and message.get('package_name', '') in ['com.android.dialer']: common.log('Execute action on phone call start (mirror): %s' % self.cmdOnPhoneCallPush) if self.cmdOnPhoneCallPush == 'pause': common.executeJSONRPCMethod('Player.PlayPause', {'play': False}) elif self.cmdOnPhoneCallPush == 'stop': common.executeJSONRPCMethod('Player.Stop')
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 showNotificationFromMessage(self, message): title = message.get( 'title', message.get('name', message.get( 'file_name', ''))) or message.get('url', '').rsplit('/', 1)[-1] body = message.get('body', message.get('address', '')).replace("\n", " / ") if not body and message['type'] == 'list': body = '{0} items'.format(len(message.get('items', []))) common.showNotification(title, body, self.notificationTime, self.notificationIcon)
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 run(self): """ Run or restart service. """ if self.pushbullet: common.log('Restarting') self.pushbullet.close() try: if not self.stg_pbAccessToken or not self.stg_pbClientIden: raise Exception(common.localise(30100)) from lib.pushbullet import Pushbullet # init pushbullet self.pushbullet = Pushbullet( access_token=self.stg_pbAccessToken, ping_timeout=6, last_modified=common.getSetting('last_modified', 0), last_modified_callback=self.setLastModified, log_callback=common.log) # get device info (also if edited by user on Pushbullet panel) self._getDevice() # setup service and pushbullet (iden, mirroring, filter) self._setupService() # start listening websocket self.pushbullet.realTimeEventStream( on_open=self.push2Notification.onOpen, on_message=self.push2Notification.onMessage, on_error=self.push2Notification.onError, on_close=self.push2Notification.onClose) common.log('Service started successfully') except Exception as ex: common.traceError() message = ' '.join(str(arg) for arg in ex.args) common.log(message, xbmc.LOGERROR) common.showNotification(common.localise(30101), message, self.serviceNotifcationTime)
def run(self): """ Run or restart service. """ if self.pushbullet: common.log('Restarting') self.pushbullet.close() try: if not self.stg_pbAccessToken or not self.stg_pbClientIden: raise Exception(common.localise(30100)) from lib.pushbullet import Pushbullet # init pushbullet self.pushbullet = Pushbullet( access_token=self.stg_pbAccessToken, ping_timeout=6, last_modified=common.getSetting('last_modified',0), last_modified_callback=self.setLastModified, log_callback=common.log) # get device info (also if edited by user on Pushbullet panel) self._getDevice() # setup service and pushbullet (iden, mirroring, filter) self._setupService() # start listening websocket self.pushbullet.realTimeEventStream(on_open=self.push2Notification.onOpen, on_message=self.push2Notification.onMessage, on_error=self.push2Notification.onError, on_close=self.push2Notification.onClose) common.log('Service started successfully') except Exception as ex: common.traceError() message = ' '.join(str(arg) for arg in ex.args) common.log(message, xbmc.LOGERROR) common.showNotification(common.localise(30101), message, self.serviceNotifcationTime)
def _onMirrorPush(self, message): if 'icon' in message: # BUILD KODI NOTIFICATION applicationNameMirrored = message.get('application_name', '') titleMirrored = message.get('title', '') # Add Title... title = applicationNameMirrored if not titleMirrored else applicationNameMirrored + ': ' title += titleMirrored # ...Body... body = message.get('body', '').rstrip('\n').replace('\n', ' / ') # ...and Icon iconPath = common.base64ToFile(message['icon'], self.imgFilePath, imgFormat='JPEG', imgSize=(96, 96)) common.showNotification(title, body, self.notificationTime, iconPath) # Action on phone call # Works only with com.android.dialer (Android stock dialer) if self.cmdOnPhoneCallPush != 'none' and message.get( 'package_name', '') in ['com.android.dialer']: common.log('Execute action on phone call start (mirror): %s' % self.cmdOnPhoneCallPush) if self.cmdOnPhoneCallPush == 'pause': common.executeJSONRPCMethod('Player.PlayPause', {'play': False}) elif self.cmdOnPhoneCallPush == 'stop': common.executeJSONRPCMethod('Player.Stop')
def onError(self, error): common.log(error, xbmc.LOGERROR) common.showNotification(common.localise(30101), error, self.notificationTime, self.notificationIcon)
def onError(self, error): common.log(error, xbmc.LOGERROR) common.showNotification(common.localise(30101), error, self.notificationTime, self.notificationIcon)