Example #1
0
    def _send(self):
        if self.config['formatted']:
            newsletter_stripped = ''.join(
                l.strip() for l in self.newsletter.splitlines())

            plaintext = 'HTML email support is required to view the newsletter.\n'
            if plexpy.CONFIG.NEWSLETTER_SELF_HOSTED and plexpy.CONFIG.HTTP_BASE_URL:
                plaintext += self._DEFAULT_BODY.format(**self.parameters)

            email_reply_msg_id = self.email_reply_msg_id if self.config[
                'threaded'] else None

            if self.email_config['notifier_id']:
                return send_notification(
                    notifier_id=self.email_config['notifier_id'],
                    subject=self.subject_formatted,
                    body=newsletter_stripped,
                    plaintext=plaintext,
                    msg_id=self.email_msg_id,
                    reply_msg_id=email_reply_msg_id)

            else:
                email = EMAIL(config=self.email_config)
                return email.notify(subject=self.subject_formatted,
                                    body=newsletter_stripped,
                                    plaintext=plaintext,
                                    msg_id=self.email_msg_id,
                                    reply_msg_id=email_reply_msg_id)
        elif self.config['notifier_id']:
            return send_notification(notifier_id=self.config['notifier_id'],
                                     subject=self.subject_formatted,
                                     body=self.body_formatted)
def notify_timeline(timeline_data=None, notify_action=None):
    if timeline_data and notify_action:
        for agent in notifiers.available_notification_agents():
            if agent["on_created"] and notify_action == "created":
                # Build and send notification
                notify_strings = build_notify_text(timeline=timeline_data, state=notify_action)
                notifiers.send_notification(
                    config_id=agent["id"],
                    subject=notify_strings[0],
                    body=notify_strings[1],
                    notify_action=notify_action,
                    script_args=notify_strings[2],
                )
                # Set the notification state in the db
                set_notify_state(session=timeline_data, state=notify_action, agent_info=agent)

    elif not timeline_data and notify_action:
        for agent in notifiers.available_notification_agents():
            if agent["on_extdown"] and notify_action == "extdown":
                # Build and send notification
                notify_strings = build_server_notify_text(state=notify_action)
                notifiers.send_notification(
                    config_id=agent["id"],
                    subject=notify_strings[0],
                    body=notify_strings[1],
                    notify_action=notify_action,
                    script_args=notify_strings[2],
                )
            if agent["on_intdown"] and notify_action == "intdown":
                # Build and send notification
                notify_strings = build_server_notify_text(state=notify_action)
                notifiers.send_notification(
                    config_id=agent["id"],
                    subject=notify_strings[0],
                    body=notify_strings[1],
                    notify_action=notify_action,
                    script_args=notify_strings[2],
                )
            if agent["on_extup"] and notify_action == "extup":
                # Build and send notification
                notify_strings = build_server_notify_text(state=notify_action)
                notifiers.send_notification(
                    config_id=agent["id"],
                    subject=notify_strings[0],
                    body=notify_strings[1],
                    notify_action=notify_action,
                    script_args=notify_strings[2],
                )
            if agent["on_intup"] and notify_action == "intup":
                # Build and send notification
                notify_strings = build_server_notify_text(state=notify_action)
                notifiers.send_notification(
                    config_id=agent["id"],
                    subject=notify_strings[0],
                    body=notify_strings[1],
                    notify_action=notify_action,
                    script_args=notify_strings[2],
                )
    else:
        logger.debug(u"PlexPy NotificationHandler :: Notify timeline called but incomplete data received.")
Example #3
0
def notify_timeline(timeline_data=None, notify_action=None):
    if timeline_data and notify_action:
        if (timeline_data['media_type'] == 'movie' and plexpy.CONFIG.MOVIE_NOTIFY_ENABLE) \
            or ((timeline_data['media_type'] == 'show' or timeline_data['media_type'] == 'episode') \
                and plexpy.CONFIG.TV_NOTIFY_ENABLE) \
            or ((timeline_data['media_type'] == 'artist' or timeline_data['media_type'] == 'track') \
                and plexpy.CONFIG.MUSIC_NOTIFY_ENABLE):

            for agent in notifiers.available_notification_agents():
                if agent['on_created'] and notify_action == 'created':
                    # Build and send notification
                    notify_strings = build_notify_text(timeline=timeline_data, state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1],
                                                notify_action=notify_action,
                                                script_args=notify_strings[2])
                    # Set the notification state in the db
                    set_notify_state(session=timeline_data, state=notify_action, agent_info=agent)

    elif not timeline_data and notify_action:
        for agent in notifiers.available_notification_agents():
            if agent['on_extdown'] and notify_action == 'extdown':
                # Build and send notification
                notify_strings = build_server_notify_text(state=notify_action)
                notifiers.send_notification(config_id=agent['id'],
                                            subject=notify_strings[0],
                                            body=notify_strings[1],
                                            notify_action=notify_action,
                                            script_args=notify_strings[2])
            if agent['on_intdown'] and notify_action == 'intdown':
                # Build and send notification
                notify_strings = build_server_notify_text(state=notify_action)
                notifiers.send_notification(config_id=agent['id'],
                                            subject=notify_strings[0],
                                            body=notify_strings[1],
                                            notify_action=notify_action,
                                            script_args=notify_strings[2])
            if agent['on_extup'] and notify_action == 'extup':
                # Build and send notification
                notify_strings = build_server_notify_text(state=notify_action)
                notifiers.send_notification(config_id=agent['id'],
                                            subject=notify_strings[0],
                                            body=notify_strings[1],
                                            notify_action=notify_action,
                                            script_args=notify_strings[2])
            if agent['on_intup'] and notify_action == 'intup':
                # Build and send notification
                notify_strings = build_server_notify_text(state=notify_action)
                notifiers.send_notification(config_id=agent['id'],
                                            subject=notify_strings[0],
                                            body=notify_strings[1],
                                            notify_action=notify_action,
                                            script_args=notify_strings[2])
    else:
        logger.debug(u"PlexPy NotificationHandler :: Notify timeline called but incomplete data received.")
Example #4
0
def notify_timeline(timeline_data=None, notify_action=None):
    if timeline_data and notify_action:
        if (timeline_data['media_type'] == 'movie' and plexpy.CONFIG.MOVIE_NOTIFY_ENABLE) \
            or ((timeline_data['media_type'] == 'show' or timeline_data['media_type'] == 'episode') \
                and plexpy.CONFIG.TV_NOTIFY_ENABLE) \
            or ((timeline_data['media_type'] == 'artist' or timeline_data['media_type'] == 'track') \
                and plexpy.CONFIG.MUSIC_NOTIFY_ENABLE):

            for agent in notifiers.available_notification_agents():
                if agent['on_created'] and notify_action == 'created':
                    # Build and send notification
                    notify_strings = build_notify_text(timeline=timeline_data,
                                                       state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])
                    # Set the notification state in the db
                    set_notify_state(session=timeline_data,
                                     state=notify_action,
                                     agent_info=agent)

    elif not timeline_data and notify_action:
        for agent in notifiers.available_notification_agents():
            if agent['on_extdown'] and notify_action == 'extdown':
                # Build and send notification
                notify_strings = build_server_notify_text(state=notify_action)
                notifiers.send_notification(config_id=agent['id'],
                                            subject=notify_strings[0],
                                            body=notify_strings[1])
            if agent['on_intdown'] and notify_action == 'intdown':
                # Build and send notification
                notify_strings = build_server_notify_text(state=notify_action)
                notifiers.send_notification(config_id=agent['id'],
                                            subject=notify_strings[0],
                                            body=notify_strings[1])
            if agent['on_extup'] and notify_action == 'extup':
                # Build and send notification
                notify_strings = build_server_notify_text(state=notify_action)
                notifiers.send_notification(config_id=agent['id'],
                                            subject=notify_strings[0],
                                            body=notify_strings[1])
            if agent['on_intup'] and notify_action == 'intup':
                # Build and send notification
                notify_strings = build_server_notify_text(state=notify_action)
                notifiers.send_notification(config_id=agent['id'],
                                            subject=notify_strings[0],
                                            body=notify_strings[1])
    else:
        logger.debug(
            u"PlexPy Notifier :: Notify timeline called but incomplete data received."
        )
Example #5
0
def notify(stream_data=None, notify_action=None):
    from plexpy import users
    
    if stream_data and notify_action:
        # Check if notifications enabled for user
        user_data = users.Users()
        user_details = user_data.get_user_friendly_name(user=stream_data['user'])

        if not user_details['do_notify']:
            return

        if (stream_data['media_type'] == 'movie' and plexpy.CONFIG.MOVIE_NOTIFY_ENABLE) \
            or (stream_data['media_type'] == 'episode' and plexpy.CONFIG.TV_NOTIFY_ENABLE):

            progress_percent = helpers.get_percent(stream_data['view_offset'], stream_data['duration'])

            for agent in notifiers.available_notification_agents():
                if agent['on_play'] and notify_action == 'play':
                    # Build and send notification
                    notify_strings = build_notify_text(session=stream_data, state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])
                    # Set the notification state in the db
                    set_notify_state(session=stream_data, state=notify_action, agent_info=agent)

                elif agent['on_stop'] and notify_action == 'stop' \
                    and (plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < plexpy.CONFIG.NOTIFY_WATCHED_PERCENT):
                    # Build and send notification
                    notify_strings = build_notify_text(session=stream_data, state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])

                    set_notify_state(session=stream_data, state=notify_action, agent_info=agent)

                elif agent['on_pause'] and notify_action == 'pause' \
                    and (plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < 99):
                    # Build and send notification
                    notify_strings = build_notify_text(session=stream_data, state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])

                    set_notify_state(session=stream_data, state=notify_action, agent_info=agent)

                elif agent['on_resume'] and notify_action == 'resume' \
                    and (plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < 99):
                    # Build and send notification
                    notify_strings = build_notify_text(session=stream_data, state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])

                    set_notify_state(session=stream_data, state=notify_action, agent_info=agent)

                elif agent['on_buffer'] and notify_action == 'buffer':
                    # Build and send notification
                    notify_strings = build_notify_text(session=stream_data, state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])

                    set_notify_state(session=stream_data, state=notify_action, agent_info=agent)

                elif agent['on_watched'] and notify_action == 'watched':
                    # Get the current states for notifications from our db
                    notify_states = get_notify_state(session=stream_data)

                    # If there is nothing in the notify_log for our agent id but it is enabled we should notify
                    if not any(d['agent_id'] == agent['id'] for d in notify_states):
                        # Build and send notification
                        notify_strings = build_notify_text(session=stream_data, state=notify_action)
                        notifiers.send_notification(config_id=agent['id'],
                                                    subject=notify_strings[0],
                                                    body=notify_strings[1])
                        # Set the notification state in the db
                        set_notify_state(session=stream_data, state=notify_action, agent_info=agent)

                    else:
                        # Check in our notify log if the notification has already been sent
                        for notify_state in notify_states:
                            if not notify_state['on_watched'] and (notify_state['agent_id'] == agent['id']):
                                # Build and send notification
                                notify_strings = build_notify_text(session=stream_data, state=notify_action)
                                notifiers.send_notification(config_id=agent['id'],
                                                            subject=notify_strings[0],
                                                            body=notify_strings[1])
                                # Set the notification state in the db
                                set_notify_state(session=stream_data, state=notify_action, agent_info=agent)

        elif (stream_data['media_type'] == 'track' and plexpy.CONFIG.MUSIC_NOTIFY_ENABLE):

            for agent in notifiers.available_notification_agents():
                if agent['on_play'] and notify_action == 'play':
                    # Build and send notification
                    notify_strings = build_notify_text(session=stream_data, state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])
                    # Set the notification state in the db
                    set_notify_state(session=stream_data, state=notify_action, agent_info=agent)

                elif agent['on_stop'] and notify_action == 'stop':
                    # Build and send notification
                    notify_strings = build_notify_text(session=stream_data, state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])
                    # Set the notification state in the db
                    set_notify_state(session=stream_data, state=notify_action, agent_info=agent)

                elif agent['on_pause'] and notify_action == 'pause':
                    # Build and send notification
                    notify_strings = build_notify_text(session=stream_data, state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])
                    # Set the notification state in the db
                    set_notify_state(session=stream_data, state=notify_action, agent_info=agent)

                elif agent['on_resume'] and notify_action == 'resume':
                    # Build and send notification
                    notify_strings = build_notify_text(session=stream_data, state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])
                    # Set the notification state in the db
                    set_notify_state(session=stream_data, state=notify_action, agent_info=agent)

                elif agent['on_buffer'] and notify_action == 'buffer':
                    # Build and send notification
                    notify_strings = build_notify_text(session=stream_data, state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])
                    # Set the notification state in the db
                    set_notify_state(session=stream_data, state=notify_action, agent_info=agent)

        elif stream_data['media_type'] == 'clip':
            pass
        else:
            #logger.debug(u"PlexPy Notifier :: Notify called with unsupported media type.")
            pass
    else:
        logger.debug(u"PlexPy Notifier :: Notify called but incomplete data received.")
def notify(stream_data=None, notify_action=None):
    from plexpy import pmsconnect, common
    
    if stream_data and notify_action:
        # Get the server name
        pms_connect = pmsconnect.PmsConnect()
        server_name = pms_connect.get_server_pref(pref='FriendlyName')

        # Build the notification heading
        notify_header = 'PlexPy (%s)' % server_name

        # Build media item title
        if stream_data['media_type'] == 'episode' or stream_data['media_type'] == 'track':
            item_title = '%s - %s' % (stream_data['grandparent_title'], stream_data['title'])
        elif stream_data['media_type'] == 'movie':
            item_title = stream_data['title']
        else:
            item_title = stream_data['title']

        if notify_action == 'play':
            logger.info('PlexPy Notifier :: %s (%s) started playing %s.' % (stream_data['friendly_name'],
                                                                           stream_data['player'], item_title))

        if stream_data['media_type'] == 'movie' or stream_data['media_type'] == 'episode':
            if plexpy.CONFIG.MOVIE_NOTIFY_ENABLE or plexpy.CONFIG.TV_NOTIFY_ENABLE:

                for agent in notifiers.available_notification_agents():
                    if agent['on_play'] and notify_action == 'play':
                        logger.debug("PlexPy Notifier :: %s agent is configured to notify on playback start." % agent['name'])
                        message = '%s (%s) started playing %s.' % \
                              (stream_data['friendly_name'], stream_data['player'], item_title)
                        notifiers.send_notification(config_id=agent['id'], subject=notify_header, body=message)
                        set_notify_state(session=stream_data, state='play', agent_info=agent)
                    elif agent['on_stop'] and notify_action == 'stop':
                        logger.debug("PlexPy Notifier :: %s agent is configured to notify on playback stop." % agent['name'])
                        message = '%s (%s) has stopped %s.' % \
                              (stream_data['friendly_name'], stream_data['player'], item_title)
                        notifiers.send_notification(config_id=agent['id'], subject=notify_header, body=message)
                        set_notify_state(session=stream_data, state='stop', agent_info=agent)
                    elif agent['on_watched'] and notify_action == 'watched':
                        notify_states = get_notify_state(session=stream_data)
                        # If there is nothing in the notify_log for our agent id but it is enabled we should notify
                        if not any(d['agent_id'] == agent['id'] for d in notify_states):
                            logger.debug("PlexPy Notifier :: %s agent is configured to notify on watched." % agent['name'])
                            message = '%s (%s) has watched %s.' % \
                                  (stream_data['friendly_name'], stream_data['player'], item_title)
                            notifiers.send_notification(config_id=agent['id'], subject=notify_header, body=message)
                            set_notify_state(session=stream_data, state='watched', agent_info=agent)
                        else:
                            # Check in our notify log if the notification has already been sent
                            for notify_state in notify_states:
                                if not notify_state['on_watched'] and (notify_state['agent_id'] == agent['id']):
                                    logger.debug("PlexPy Notifier :: %s agent is configured to notify on watched." % agent['name'])
                                    message = '%s (%s) has watched %s.' % \
                                          (stream_data['friendly_name'], stream_data['player'], item_title)
                                    notifiers.send_notification(config_id=agent['id'], subject=notify_header, body=message)
                                    set_notify_state(session=stream_data, state='watched', agent_info=agent)

        elif stream_data['media_type'] == 'track':
            if plexpy.CONFIG.MUSIC_NOTIFY_ENABLE:

                for agent in notifiers.available_notification_agents():
                    if agent['on_play'] and notify_action == 'play':
                        logger.debug("PlexPy Notifier :: %s agent is configured to notify on playback start." % agent['name'])
                        message = '%s (%s) started playing %s.' % \
                              (stream_data['friendly_name'], stream_data['player'], item_title)
                        notifiers.send_notification(config_id=agent['id'], subject=notify_header, body=message)
                        set_notify_state(session=stream_data, state='play', agent_info=agent)
                    elif agent['on_stop'] and notify_action == 'stop':
                        logger.debug("PlexPy Notifier :: %s agent is configured to notify on playback stop." % agent['name'])
                        message = '%s (%s) has stopped %s.' % \
                              (stream_data['friendly_name'], stream_data['player'], item_title)
                        notifiers.send_notification(config_id=agent['id'], subject=notify_header, body=message)
                        set_notify_state(session=stream_data, state='stop', agent_info=agent)

        elif stream_data['media_type'] == 'clip':
            pass
        else:
            logger.debug(u"PlexPy Notifier :: Notify called with unsupported media type.")
            pass
    else:
        logger.debug(u"PlexPy Notifier :: Notify called but incomplete data received.")
Example #7
0
def notify(stream_data=None, notify_action=None):
    from plexpy import users

    if stream_data and notify_action:
        # Check if notifications enabled for user
        user_data = users.Users()
        user_details = user_data.get_user_friendly_name(
            user=stream_data['user'])

        if not user_details['do_notify']:
            return

        if (stream_data['media_type'] == 'movie' and plexpy.CONFIG.MOVIE_NOTIFY_ENABLE) \
            or (stream_data['media_type'] == 'episode' and plexpy.CONFIG.TV_NOTIFY_ENABLE):

            progress_percent = helpers.get_percent(stream_data['view_offset'],
                                                   stream_data['duration'])

            for agent in notifiers.available_notification_agents():
                if agent['on_play'] and notify_action == 'play':
                    # Build and send notification
                    notify_strings = build_notify_text(session=stream_data,
                                                       state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])
                    # Set the notification state in the db
                    set_notify_state(session=stream_data,
                                     state=notify_action,
                                     agent_info=agent)

                elif agent['on_stop'] and notify_action == 'stop' \
                    and (plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < plexpy.CONFIG.NOTIFY_WATCHED_PERCENT):
                    # Build and send notification
                    notify_strings = build_notify_text(session=stream_data,
                                                       state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])

                    set_notify_state(session=stream_data,
                                     state=notify_action,
                                     agent_info=agent)

                elif agent['on_pause'] and notify_action == 'pause' \
                    and (plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < 99):
                    # Build and send notification
                    notify_strings = build_notify_text(session=stream_data,
                                                       state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])

                    set_notify_state(session=stream_data,
                                     state=notify_action,
                                     agent_info=agent)

                elif agent['on_resume'] and notify_action == 'resume' \
                    and (plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < 99):
                    # Build and send notification
                    notify_strings = build_notify_text(session=stream_data,
                                                       state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])

                    set_notify_state(session=stream_data,
                                     state=notify_action,
                                     agent_info=agent)

                elif agent['on_buffer'] and notify_action == 'buffer':
                    # Build and send notification
                    notify_strings = build_notify_text(session=stream_data,
                                                       state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])

                    set_notify_state(session=stream_data,
                                     state=notify_action,
                                     agent_info=agent)

                elif agent['on_watched'] and notify_action == 'watched':
                    # Get the current states for notifications from our db
                    notify_states = get_notify_state(session=stream_data)

                    # If there is nothing in the notify_log for our agent id but it is enabled we should notify
                    if not any(d['agent_id'] == agent['id']
                               for d in notify_states):
                        # Build and send notification
                        notify_strings = build_notify_text(session=stream_data,
                                                           state=notify_action)
                        notifiers.send_notification(config_id=agent['id'],
                                                    subject=notify_strings[0],
                                                    body=notify_strings[1])
                        # Set the notification state in the db
                        set_notify_state(session=stream_data,
                                         state=notify_action,
                                         agent_info=agent)

                    else:
                        # Check in our notify log if the notification has already been sent
                        for notify_state in notify_states:
                            if not notify_state['on_watched'] and (
                                    notify_state['agent_id'] == agent['id']):
                                # Build and send notification
                                notify_strings = build_notify_text(
                                    session=stream_data, state=notify_action)
                                notifiers.send_notification(
                                    config_id=agent['id'],
                                    subject=notify_strings[0],
                                    body=notify_strings[1])
                                # Set the notification state in the db
                                set_notify_state(session=stream_data,
                                                 state=notify_action,
                                                 agent_info=agent)

        elif (stream_data['media_type'] == 'track'
              and plexpy.CONFIG.MUSIC_NOTIFY_ENABLE):

            for agent in notifiers.available_notification_agents():
                if agent['on_play'] and notify_action == 'play':
                    # Build and send notification
                    notify_strings = build_notify_text(session=stream_data,
                                                       state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])
                    # Set the notification state in the db
                    set_notify_state(session=stream_data,
                                     state=notify_action,
                                     agent_info=agent)

                elif agent['on_stop'] and notify_action == 'stop':
                    # Build and send notification
                    notify_strings = build_notify_text(session=stream_data,
                                                       state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])
                    # Set the notification state in the db
                    set_notify_state(session=stream_data,
                                     state=notify_action,
                                     agent_info=agent)

                elif agent['on_pause'] and notify_action == 'pause':
                    # Build and send notification
                    notify_strings = build_notify_text(session=stream_data,
                                                       state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])
                    # Set the notification state in the db
                    set_notify_state(session=stream_data,
                                     state=notify_action,
                                     agent_info=agent)

                elif agent['on_resume'] and notify_action == 'resume':
                    # Build and send notification
                    notify_strings = build_notify_text(session=stream_data,
                                                       state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])
                    # Set the notification state in the db
                    set_notify_state(session=stream_data,
                                     state=notify_action,
                                     agent_info=agent)

                elif agent['on_buffer'] and notify_action == 'buffer':
                    # Build and send notification
                    notify_strings = build_notify_text(session=stream_data,
                                                       state=notify_action)
                    notifiers.send_notification(config_id=agent['id'],
                                                subject=notify_strings[0],
                                                body=notify_strings[1])
                    # Set the notification state in the db
                    set_notify_state(session=stream_data,
                                     state=notify_action,
                                     agent_info=agent)

        elif stream_data['media_type'] == 'clip':
            pass
        else:
            #logger.debug(u"PlexPy Notifier :: Notify called with unsupported media type.")
            pass
    else:
        logger.debug(
            u"PlexPy Notifier :: Notify called but incomplete data received.")
Example #8
0
def notify(stream_data=None, notify_action=None):
    from plexpy import users

    if stream_data and notify_action:
        # Check if notifications enabled for user
        user_data = users.Users()
        user_details = user_data.get_user_friendly_name(user=stream_data["user"])

        if not user_details["do_notify"]:
            return

        if stream_data["media_type"] == "movie" or stream_data["media_type"] == "episode":
            if plexpy.CONFIG.MOVIE_NOTIFY_ENABLE or plexpy.CONFIG.TV_NOTIFY_ENABLE:

                progress_percent = helpers.get_percent(stream_data["view_offset"], stream_data["duration"])

                for agent in notifiers.available_notification_agents():
                    if agent["on_play"] and notify_action == "play":
                        # Build and send notification
                        notify_strings = build_notify_text(session=stream_data, state=notify_action)
                        notifiers.send_notification(
                            config_id=agent["id"], subject=notify_strings[0], body=notify_strings[1]
                        )
                        # Set the notification state in the db
                        set_notify_state(session=stream_data, state="play", agent_info=agent)

                    elif (
                        agent["on_stop"]
                        and notify_action == "stop"
                        and (
                            plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < plexpy.CONFIG.NOTIFY_WATCHED_PERCENT
                        )
                    ):
                        # Build and send notification
                        notify_strings = build_notify_text(session=stream_data, state=notify_action)
                        notifiers.send_notification(
                            config_id=agent["id"], subject=notify_strings[0], body=notify_strings[1]
                        )

                        set_notify_state(session=stream_data, state="stop", agent_info=agent)

                    elif (
                        agent["on_pause"]
                        and notify_action == "pause"
                        and (plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < 99)
                    ):
                        # Build and send notification
                        notify_strings = build_notify_text(session=stream_data, state=notify_action)
                        notifiers.send_notification(
                            config_id=agent["id"], subject=notify_strings[0], body=notify_strings[1]
                        )

                        set_notify_state(session=stream_data, state="pause", agent_info=agent)

                    elif (
                        agent["on_resume"]
                        and notify_action == "resume"
                        and (plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < 99)
                    ):
                        # Build and send notification
                        notify_strings = build_notify_text(session=stream_data, state=notify_action)
                        notifiers.send_notification(
                            config_id=agent["id"], subject=notify_strings[0], body=notify_strings[1]
                        )

                        set_notify_state(session=stream_data, state="resume", agent_info=agent)

                    elif agent["on_buffer"] and notify_action == "buffer":
                        # Build and send notification
                        notify_strings = build_notify_text(session=stream_data, state=notify_action)
                        notifiers.send_notification(
                            config_id=agent["id"], subject=notify_strings[0], body=notify_strings[1]
                        )

                        set_notify_state(session=stream_data, state="buffer", agent_info=agent)

                    elif agent["on_watched"] and notify_action == "watched":
                        # Get the current states for notifications from our db
                        notify_states = get_notify_state(session=stream_data)

                        # If there is nothing in the notify_log for our agent id but it is enabled we should notify
                        if not any(d["agent_id"] == agent["id"] for d in notify_states):
                            # Build and send notification
                            notify_strings = build_notify_text(session=stream_data, state=notify_action)
                            notifiers.send_notification(
                                config_id=agent["id"], subject=notify_strings[0], body=notify_strings[1]
                            )
                            # Set the notification state in the db
                            set_notify_state(session=stream_data, state="watched", agent_info=agent)

                        else:
                            # Check in our notify log if the notification has already been sent
                            for notify_state in notify_states:
                                if not notify_state["on_watched"] and (notify_state["agent_id"] == agent["id"]):
                                    # Build and send notification
                                    notify_strings = build_notify_text(session=stream_data, state=notify_action)
                                    notifiers.send_notification(
                                        config_id=agent["id"], subject=notify_strings[0], body=notify_strings[1]
                                    )
                                    # Set the notification state in the db
                                    set_notify_state(session=stream_data, state="watched", agent_info=agent)

        elif stream_data["media_type"] == "track":
            if plexpy.CONFIG.MUSIC_NOTIFY_ENABLE:

                for agent in notifiers.available_notification_agents():
                    if agent["on_play"] and notify_action == "play":
                        # Build and send notification
                        notify_strings = build_notify_text(session=stream_data, state=notify_action)
                        notifiers.send_notification(
                            config_id=agent["id"], subject=notify_strings[0], body=notify_strings[1]
                        )
                        # Set the notification state in the db
                        set_notify_state(session=stream_data, state="play", agent_info=agent)

                    elif agent["on_stop"] and notify_action == "stop":
                        # Build and send notification
                        notify_strings = build_notify_text(session=stream_data, state=notify_action)
                        notifiers.send_notification(
                            config_id=agent["id"], subject=notify_strings[0], body=notify_strings[1]
                        )
                        # Set the notification state in the db
                        set_notify_state(session=stream_data, state="stop", agent_info=agent)

                    elif agent["on_pause"] and notify_action == "pause":
                        # Build and send notification
                        notify_strings = build_notify_text(session=stream_data, state=notify_action)
                        notifiers.send_notification(
                            config_id=agent["id"], subject=notify_strings[0], body=notify_strings[1]
                        )
                        # Set the notification state in the db
                        set_notify_state(session=stream_data, state="pause", agent_info=agent)

                    elif agent["on_resume"] and notify_action == "resume":
                        # Build and send notification
                        notify_strings = build_notify_text(session=stream_data, state=notify_action)
                        notifiers.send_notification(
                            config_id=agent["id"], subject=notify_strings[0], body=notify_strings[1]
                        )
                        # Set the notification state in the db
                        set_notify_state(session=stream_data, state="resume", agent_info=agent)

                    elif agent["on_buffer"] and notify_action == "buffer":
                        # Build and send notification
                        notify_strings = build_notify_text(session=stream_data, state=notify_action)
                        notifiers.send_notification(
                            config_id=agent["id"], subject=notify_strings[0], body=notify_strings[1]
                        )
                        # Set the notification state in the db
                        set_notify_state(session=stream_data, state="buffer", agent_info=agent)

        elif stream_data["media_type"] == "clip":
            pass
        else:
            logger.debug(u"PlexPy Notifier :: Notify called with unsupported media type.")
            pass
    else:
        logger.debug(u"PlexPy Notifier :: Notify called but incomplete data received.")
Example #9
0
def notify(stream_data=None, notify_action=None):
    from plexpy import datafactory
    
    if stream_data and notify_action:
        # Check if notifications enabled for user
        data_factory = datafactory.DataFactory()
        user_details = data_factory.get_user_friendly_name(user=stream_data['user'])

        if not user_details['do_notify']:
            return

        if stream_data['media_type'] == 'movie' or stream_data['media_type'] == 'episode':
            if plexpy.CONFIG.MOVIE_NOTIFY_ENABLE or plexpy.CONFIG.TV_NOTIFY_ENABLE:

                for agent in notifiers.available_notification_agents():
                    if agent['on_play'] and notify_action == 'play':
                        # Build and send notification
                        notify_strings = build_notify_text(session=stream_data, state=notify_action)
                        notifiers.send_notification(config_id=agent['id'],
                                                    subject=notify_strings[0],
                                                    body=notify_strings[1])
                        # Set the notification state in the db
                        set_notify_state(session=stream_data, state='play', agent_info=agent)

                    elif agent['on_stop'] and notify_action == 'stop':
                        # Build and send notification
                        notify_strings = build_notify_text(session=stream_data, state=notify_action)
                        notifiers.send_notification(config_id=agent['id'],
                                                    subject=notify_strings[0],
                                                    body=notify_strings[1])

                        set_notify_state(session=stream_data, state='stop', agent_info=agent)

                    elif agent['on_watched'] and notify_action == 'watched':
                        # Get the current states for notifications from our db
                        notify_states = get_notify_state(session=stream_data)

                        # If there is nothing in the notify_log for our agent id but it is enabled we should notify
                        if not any(d['agent_id'] == agent['id'] for d in notify_states):
                            # Build and send notification
                            notify_strings = build_notify_text(session=stream_data, state=notify_action)
                            notifiers.send_notification(config_id=agent['id'],
                                                        subject=notify_strings[0],
                                                        body=notify_strings[1])
                            # Set the notification state in the db
                            set_notify_state(session=stream_data, state='watched', agent_info=agent)

                        else:
                            # Check in our notify log if the notification has already been sent
                            for notify_state in notify_states:
                                if not notify_state['on_watched'] and (notify_state['agent_id'] == agent['id']):
                                    # Build and send notification
                                    notify_strings = build_notify_text(session=stream_data, state=notify_action)
                                    notifiers.send_notification(config_id=agent['id'],
                                                                subject=notify_strings[0],
                                                                body=notify_strings[1])
                                    # Set the notification state in the db
                                    set_notify_state(session=stream_data, state='watched', agent_info=agent)

        elif stream_data['media_type'] == 'track':
            if plexpy.CONFIG.MUSIC_NOTIFY_ENABLE:

                for agent in notifiers.available_notification_agents():
                    if agent['on_play'] and notify_action == 'play':
                        # Build and send notification
                        notify_strings = build_notify_text(session=stream_data, state=notify_action)
                        notifiers.send_notification(config_id=agent['id'],
                                                    subject=notify_strings[0],
                                                    body=notify_strings[1])
                        # Set the notification state in the db
                        set_notify_state(session=stream_data, state='play', agent_info=agent)

                    elif agent['on_stop'] and notify_action == 'stop':
                        # Build and send notification
                        notify_strings = build_notify_text(session=stream_data, state=notify_action)
                        notifiers.send_notification(config_id=agent['id'],
                                                    subject=notify_strings[0],
                                                    body=notify_strings[1])
                        # Set the notification state in the db
                        set_notify_state(session=stream_data, state='stop', agent_info=agent)

        elif stream_data['media_type'] == 'clip':
            pass
        else:
            logger.debug(u"PlexPy Notifier :: Notify called with unsupported media type.")
            pass
    else:
        logger.debug(u"PlexPy Notifier :: Notify called but incomplete data received.")
Example #10
0
def notify_timeline(timeline_data=None, notify_action=None):
    if timeline_data and notify_action:
        if (
            (timeline_data["media_type"] == "movie" and plexpy.CONFIG.MOVIE_NOTIFY_ENABLE)
            or (
                (timeline_data["media_type"] == "show" or timeline_data["media_type"] == "episode")
                and plexpy.CONFIG.TV_NOTIFY_ENABLE
            )
            or (
                (timeline_data["media_type"] == "artist" or timeline_data["media_type"] == "track")
                and plexpy.CONFIG.MUSIC_NOTIFY_ENABLE
            )
        ):

            for agent in notifiers.available_notification_agents():
                if agent["on_created"] and notify_action == "created":
                    # Build and send notification
                    notify_strings = build_notify_text(timeline=timeline_data, state=notify_action)
                    notifiers.send_notification(
                        config_id=agent["id"],
                        subject=notify_strings[0],
                        body=notify_strings[1],
                        notify_action=notify_action,
                        script_args=notify_strings[2],
                    )
                    # Set the notification state in the db
                    set_notify_state(session=timeline_data, state=notify_action, agent_info=agent)

    elif not timeline_data and notify_action:
        for agent in notifiers.available_notification_agents():
            if agent["on_extdown"] and notify_action == "extdown":
                # Build and send notification
                notify_strings = build_server_notify_text(state=notify_action)
                notifiers.send_notification(
                    config_id=agent["id"],
                    subject=notify_strings[0],
                    body=notify_strings[1],
                    notify_action=notify_action,
                    script_args=notify_strings[2],
                )
            if agent["on_intdown"] and notify_action == "intdown":
                # Build and send notification
                notify_strings = build_server_notify_text(state=notify_action)
                notifiers.send_notification(
                    config_id=agent["id"],
                    subject=notify_strings[0],
                    body=notify_strings[1],
                    notify_action=notify_action,
                    script_args=notify_strings[2],
                )
            if agent["on_extup"] and notify_action == "extup":
                # Build and send notification
                notify_strings = build_server_notify_text(state=notify_action)
                notifiers.send_notification(
                    config_id=agent["id"],
                    subject=notify_strings[0],
                    body=notify_strings[1],
                    notify_action=notify_action,
                    script_args=notify_strings[2],
                )
            if agent["on_intup"] and notify_action == "intup":
                # Build and send notification
                notify_strings = build_server_notify_text(state=notify_action)
                notifiers.send_notification(
                    config_id=agent["id"],
                    subject=notify_strings[0],
                    body=notify_strings[1],
                    notify_action=notify_action,
                    script_args=notify_strings[2],
                )
    else:
        logger.debug(u"PlexPy NotificationHandler :: Notify timeline called but incomplete data received.")