Example #1
0
    def process(self, opcode, data):
        if opcode not in self.opcode_data:
            return False

        try:
            logger.websocket_debug(data)
            info = json.loads(data.decode('utf-8'))
        except Exception as e:
            logger.warn(u"Tautulli WebSocket :: %s: Error decoding message from websocket: %s" % (self.server.CONFIG.PMS_NAME, e))
            logger.websocket_error(data)
            return False

        info = info.get('NotificationContainer', info)
        type = info.get('type')

        if not type:
            return False

        if type == 'playing':
            time_line = info.get('PlaySessionStateNotification', info.get('_children', {}))

            if not time_line:
                logger.debug(u"Tautulli WebSocket :: %s: Session found but unable to get timeline data." % self.server.CONFIG.PMS_NAME)
                return False

            try:
                activity = activity_handler.ActivityHandler(self.server, timeline=time_line[0])
                activity.process()
            except Exception as e:
                logger.error(u"Tautulli WebSocket :: %s: Failed to process session data: %s." % (self.server.CONFIG.PMS_NAME, e))

        if type == 'timeline':
            time_line = info.get('TimelineEntry', info.get('_children', {}))

            if not time_line:
                logger.debug(u"Tautulli WebSocket :: %s: Timeline event found but unable to get timeline data." % self.server.CONFIG.PMS_NAME)
                return False

            try:
                activity = activity_handler.TimelineHandler(self.server, timeline=time_line[0])
                activity.process()
            except Exception as e:
                logger.error(u"Tautulli WebSocket :: %s: Failed to process timeline data: %s." % (self.server.CONFIG.PMS_NAME, e))

        return True
Example #2
0
def process(opcode, data):
    from plexpy import activity_handler

    if opcode not in opcode_data:
        return False

    try:
        info = json.loads(data)
    except Exception as ex:
        logger.warn(
            u'PlexPy WebSocket :: Error decoding message from websocket: %s' %
            ex)
        logger.debug(data)
        return False

    type = info.get('type')

    if not type:
        return False

    if type == 'playing':
        # logger.debug('%s.playing %s' % (name, info))
        try:
            time_line = info.get('_children')
        except:
            logger.debug(
                u"PlexPy WebSocket :: Session found but unable to get timeline data."
            )
            return False

        activity = activity_handler.ActivityHandler(timeline=time_line[0])
        activity.process()

    #if type == 'timeline':
    #    try:
    #        time_line = info.get('_children')
    #    except:
    #        logger.debug(u"PlexPy WebSocket :: Timeline event found but unable to get timeline data.")
    #        return False

    #    activity = activity_handler.TimelineHandler(timeline=time_line[0])
    #    activity.process()

    return True