From dff493c8d97f00695169d2fd1517b0bee73e1a9d Mon Sep 17 00:00:00 2001 From: Jonathan Wong Date: Tue, 29 Sep 2015 09:24:23 -0700 Subject: [PATCH] Change to notify stopped only if less than watched percent * Also fix paused notifications sending at the end of items (right before stopping) --- data/interfaces/default/settings.html | 6 ++++++ plexpy/config.py | 1 + plexpy/notification_handler.py | 13 +++++++++---- plexpy/webserve.py | 3 ++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/data/interfaces/default/settings.html b/data/interfaces/default/settings.html index 000084b0..3adc935e 100644 --- a/data/interfaces/default/settings.html +++ b/data/interfaces/default/settings.html @@ -496,6 +496,12 @@ available_notification_agents = notifiers.available_notification_agents()

Set the progress percentage of when a watched notification should be triggered. Minimum 50, Maximum 95.

+
+ +

Disable to prevent consecutive notifications (i.e. both watched & stopped notifications).

+

Custom Notification Messages

diff --git a/plexpy/config.py b/plexpy/config.py index c5e1c8a2..6810a693 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -122,6 +122,7 @@ _CONFIG_DEFINITIONS = { 'NMA_ON_RESUME': (int, 'NMA', 0), 'NMA_ON_BUFFER': (int, 'NMA', 0), 'NMA_ON_WATCHED': (int, 'NMA', 0), + 'NOTIFY_CONSECUTIVE': (int, 'Monitoring', 1), 'NOTIFY_WATCHED_PERCENT': (int, 'Monitoring', 85), 'NOTIFY_ON_START_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'), 'NOTIFY_ON_START_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) started playing {title}.'), diff --git a/plexpy/notification_handler.py b/plexpy/notification_handler.py index 1e751bac..2f2637cc 100644 --- a/plexpy/notification_handler.py +++ b/plexpy/notification_handler.py @@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License # along with PlexPy. If not, see . -from plexpy import logger, config, notifiers, database +from plexpy import logger, config, notifiers, database, helpers import plexpy import time @@ -33,6 +33,8 @@ def notify(stream_data=None, notify_action=None): 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 @@ -43,7 +45,8 @@ def notify(stream_data=None, notify_action=None): # 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': + 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'], @@ -52,7 +55,8 @@ def notify(stream_data=None, notify_action=None): set_notify_state(session=stream_data, state='stop', agent_info=agent) - elif agent['on_pause'] and notify_action == 'pause': + 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'], @@ -61,7 +65,8 @@ def notify(stream_data=None, notify_action=None): set_notify_state(session=stream_data, state='pause', agent_info=agent) - elif agent['on_resume'] and notify_action == 'resume': + 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'], diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 46bb3dc2..3129e493 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -439,6 +439,7 @@ class WebInterface(object): "music_logging_enable": checked(plexpy.CONFIG.MUSIC_LOGGING_ENABLE), "logging_ignore_interval": plexpy.CONFIG.LOGGING_IGNORE_INTERVAL, "pms_is_remote": checked(plexpy.CONFIG.PMS_IS_REMOTE), + "notify_consecutive": checked(plexpy.CONFIG.NOTIFY_CONSECUTIVE), "notify_watched_percent": plexpy.CONFIG.NOTIFY_WATCHED_PERCENT, "notify_on_start_subject_text": plexpy.CONFIG.NOTIFY_ON_START_SUBJECT_TEXT, "notify_on_start_body_text": plexpy.CONFIG.NOTIFY_ON_START_BODY_TEXT, @@ -476,7 +477,7 @@ class WebInterface(object): "tv_notify_on_stop", "movie_notify_on_stop", "music_notify_on_stop", "tv_notify_on_pause", "movie_notify_on_pause", "music_notify_on_pause", "refresh_users_on_startup", "ip_logging_enable", "video_logging_enable", "music_logging_enable", "pms_is_remote", "home_stats_type", - "group_history_tables" + "group_history_tables", "notify_consecutive" ] for checked_config in checked_configs: if checked_config not in kwargs: