Change to notify stopped only if less than watched percent

* Also fix paused notifications sending at the end of items (right
before stopping)
This commit is contained in:
Jonathan Wong 2015-09-29 09:24:23 -07:00
parent f7bc208fd1
commit dff493c8d9
4 changed files with 18 additions and 5 deletions

View file

@ -496,6 +496,12 @@ available_notification_agents = notifiers.available_notification_agents()
</div> </div>
<p class="help-block">Set the progress percentage of when a watched notification should be triggered. Minimum 50, Maximum 95.</p> <p class="help-block">Set the progress percentage of when a watched notification should be triggered. Minimum 50, Maximum 95.</p>
</div> </div>
<div class="checkbox">
<label>
<input type="checkbox" name="notify_consecutive" id="notify_consecutive" value="1" ${config['notify_consecutive']}> Allow Consecutive Notifications
</label>
<p class="help-block">Disable to prevent consecutive notifications (i.e. both watched &amp; stopped notifications).</p>
</div>
<div class="padded-header"> <div class="padded-header">
<h3>Custom Notification Messages</h3> <h3>Custom Notification Messages</h3>

View file

@ -122,6 +122,7 @@ _CONFIG_DEFINITIONS = {
'NMA_ON_RESUME': (int, 'NMA', 0), 'NMA_ON_RESUME': (int, 'NMA', 0),
'NMA_ON_BUFFER': (int, 'NMA', 0), 'NMA_ON_BUFFER': (int, 'NMA', 0),
'NMA_ON_WATCHED': (int, 'NMA', 0), 'NMA_ON_WATCHED': (int, 'NMA', 0),
'NOTIFY_CONSECUTIVE': (int, 'Monitoring', 1),
'NOTIFY_WATCHED_PERCENT': (int, 'Monitoring', 85), 'NOTIFY_WATCHED_PERCENT': (int, 'Monitoring', 85),
'NOTIFY_ON_START_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'), 'NOTIFY_ON_START_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_START_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) started playing {title}.'), 'NOTIFY_ON_START_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) started playing {title}.'),

View file

@ -13,7 +13,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>. # along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
from plexpy import logger, config, notifiers, database from plexpy import logger, config, notifiers, database, helpers
import plexpy import plexpy
import time 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 stream_data['media_type'] == 'movie' or stream_data['media_type'] == 'episode':
if plexpy.CONFIG.MOVIE_NOTIFY_ENABLE or plexpy.CONFIG.TV_NOTIFY_ENABLE: 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(): for agent in notifiers.available_notification_agents():
if agent['on_play'] and notify_action == 'play': if agent['on_play'] and notify_action == 'play':
# Build and send notification # Build and send notification
@ -43,7 +45,8 @@ def notify(stream_data=None, notify_action=None):
# Set the notification state in the db # Set the notification state in the db
set_notify_state(session=stream_data, state='play', agent_info=agent) 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 # Build and send notification
notify_strings = build_notify_text(session=stream_data, state=notify_action) notify_strings = build_notify_text(session=stream_data, state=notify_action)
notifiers.send_notification(config_id=agent['id'], 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) 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 # Build and send notification
notify_strings = build_notify_text(session=stream_data, state=notify_action) notify_strings = build_notify_text(session=stream_data, state=notify_action)
notifiers.send_notification(config_id=agent['id'], 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) 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 # Build and send notification
notify_strings = build_notify_text(session=stream_data, state=notify_action) notify_strings = build_notify_text(session=stream_data, state=notify_action)
notifiers.send_notification(config_id=agent['id'], notifiers.send_notification(config_id=agent['id'],

View file

@ -439,6 +439,7 @@ class WebInterface(object):
"music_logging_enable": checked(plexpy.CONFIG.MUSIC_LOGGING_ENABLE), "music_logging_enable": checked(plexpy.CONFIG.MUSIC_LOGGING_ENABLE),
"logging_ignore_interval": plexpy.CONFIG.LOGGING_IGNORE_INTERVAL, "logging_ignore_interval": plexpy.CONFIG.LOGGING_IGNORE_INTERVAL,
"pms_is_remote": checked(plexpy.CONFIG.PMS_IS_REMOTE), "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_watched_percent": plexpy.CONFIG.NOTIFY_WATCHED_PERCENT,
"notify_on_start_subject_text": plexpy.CONFIG.NOTIFY_ON_START_SUBJECT_TEXT, "notify_on_start_subject_text": plexpy.CONFIG.NOTIFY_ON_START_SUBJECT_TEXT,
"notify_on_start_body_text": plexpy.CONFIG.NOTIFY_ON_START_BODY_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_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", "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", "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: for checked_config in checked_configs:
if checked_config not in kwargs: if checked_config not in kwargs: