Example #1
0
    def onMessage(self, message):
        try:
            from json import dumps
            common.log('New push (%s) received: %s' %
                       (message['type'], dumps(message)))

            if message['type'] == 'mirror':
                return self._onMirrorPush(message)

            # kodi action (pause, stop, skip) on push dismiss (from devices)
            elif message['type'] == 'dismissal':
                return self._onDismissPush(message, self.cmdOnDismissPush)

            elif message['type'] == 'link':
                return self._onMessageLink(message)

            elif message['type'] == 'file':
                return self._onMessageFile(message)

            elif message['type'] == 'note':
                return self._onMessageNote(message)

            elif message['type'] == 'address':
                return self._onMessageAddress(message)

            elif message['type'] == 'list':
                return self._onMessageList(message)

        except Exception as ex:
            common.traceError()
            common.log(' '.join(str(arg) for arg in ex.args), xbmc.LOGERROR)
    def onMessage(self, message):
        try:
            from json import dumps
            common.log('New push (%s) received: %s' % (message['type'], dumps(message)))

            if message['type'] == 'mirror':
                return self._onMirrorPush(message)

            # kodi action (pause, stop, skip) on push dismiss (from devices)
            elif message['type'] == 'dismissal':
                return self._onDismissPush(message, self.cmdOnDismissPush)

            elif message['type'] == 'link':
                return self._onMessageLink(message)

            elif message['type'] == 'file':
                return self._onMessageFile(message)

            elif message['type'] == 'note':
                return self._onMessageNote(message)

            elif message['type'] == 'address':
                return self._onMessageAddress(message)

            elif message['type'] == 'list':
                return self._onMessageList(message)


        except Exception as ex:
            common.traceError()
            common.log(' '.join(str(arg) for arg in ex.args), xbmc.LOGERROR)
Example #3
0
    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 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)
            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)

if __name__ == "__main__":
    import sys

    if sys.argv[0] == 'service.pushbullet' and len(sys.argv) < 2:
        import main
        main.main()

    try:
        args = None
        if len(sys.argv) > 1:
            args = sys.argv[1:]

        if args:
            import main
            main.handleArg(args[0])
        else:
            Service()
    except:
        common.traceError()
                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)


if __name__ == "__main__":
    import sys

    if sys.argv[0] == 'service.pushbullet' and len(sys.argv) < 2:
        import main
        main.main()

    try:
        args = None
        if len(sys.argv) > 1:
            args = sys.argv[1:]

        if args:
            import main
            main.handleArg(args[0])
        else:
            Service()
    except:
        common.traceError()