Only preview notification text for valid media types

This commit is contained in:
JonnyWong16 2016-11-04 23:30:30 -07:00
parent 580595e5fa
commit 0ab9cdf97c
4 changed files with 39 additions and 20 deletions

View file

@ -1,4 +1,3 @@
% if text:
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
@ -6,6 +5,7 @@
<h4 class="modal-title">Notification Text Preview</h4> <h4 class="modal-title">Notification Text Preview</h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">
% if text:
% for item in text: % for item in text:
<div style="padding-bottom: 10px;"> <div style="padding-bottom: 10px;">
<h4>${item['media_type'].capitalize()}</h4> <h4>${item['media_type'].capitalize()}</h4>
@ -15,9 +15,11 @@
% endif % endif
</div> </div>
% endfor % endfor
% else:
<div style="text-align: center;"><i class="fa fa-exclamation-circle"></i> Failed to generate preview.</div>
% endif
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
</div> </div>
</div> </div>
</div> </div>
% endif

View file

@ -580,7 +580,7 @@ def build_notify_text(subject='', body='', notify_action=None, parameters=None,
elif media_type == 'track': elif media_type == 'track':
pattern = re.compile(all_tags.replace('<track>.*?</track>', '<track>|</track>'), re.IGNORECASE | re.DOTALL) pattern = re.compile(all_tags.replace('<track>.*?</track>', '<track>|</track>'), re.IGNORECASE | re.DOTALL)
else: else:
pattern = None pattern = re.compile(all_tags, re.IGNORECASE | re.DOTALL)
if pattern: if pattern:
# Remove the unwanted tags and strip any unmatch tags too. # Remove the unwanted tags and strip any unmatch tags too.

View file

@ -170,105 +170,120 @@ def available_notification_actions():
'description': 'Trigger a notification when a stream is started.', 'description': 'Trigger a notification when a stream is started.',
'subject': 'PlexPy ({server_name})', 'subject': 'PlexPy ({server_name})',
'body': '{user} ({player}) started playing {title}.', 'body': '{user} ({player}) started playing {title}.',
'icon': 'fa-play' 'icon': 'fa-play',
'media_types': ('movie', 'episode', 'track')
}, },
{'label': 'Playback Stop', {'label': 'Playback Stop',
'name': 'on_stop', 'name': 'on_stop',
'description': 'Trigger a notification when a stream is stopped.', 'description': 'Trigger a notification when a stream is stopped.',
'subject': 'PlexPy ({server_name})', 'subject': 'PlexPy ({server_name})',
'body': '{user} ({player}) has stopped {title}.', 'body': '{user} ({player}) has stopped {title}.',
'icon': 'fa-stop' 'icon': 'fa-stop',
'media_types': ('movie', 'episode', 'track')
}, },
{'label': 'Playback Pause', {'label': 'Playback Pause',
'name': 'on_pause', 'name': 'on_pause',
'description': 'Trigger a notification when a stream is puased.', 'description': 'Trigger a notification when a stream is puased.',
'subject': 'PlexPy ({server_name})', 'subject': 'PlexPy ({server_name})',
'body': '{user} ({player}) has paused {title}.', 'body': '{user} ({player}) has paused {title}.',
'icon': 'fa-pause' 'icon': 'fa-pause',
'media_types': ('movie', 'episode', 'track')
}, },
{'label': 'Playback Resume', {'label': 'Playback Resume',
'name': 'on_resume', 'name': 'on_resume',
'description': 'Trigger a notification when a stream is resumed.', 'description': 'Trigger a notification when a stream is resumed.',
'subject': 'PlexPy ({server_name})', 'subject': 'PlexPy ({server_name})',
'body': '{user} ({player}) has resumed {title}.', 'body': '{user} ({player}) has resumed {title}.',
'icon': 'fa-play' 'icon': 'fa-play',
'media_types': ('movie', 'episode', 'track')
}, },
{'label': 'Watched', {'label': 'Watched',
'name': 'on_watched', 'name': 'on_watched',
'description': 'Trigger a notification when a video stream reaches the specified watch percentage.', 'description': 'Trigger a notification when a video stream reaches the specified watch percentage.',
'subject': 'PlexPy ({server_name})', 'subject': 'PlexPy ({server_name})',
'body': '{user} ({player}) has watched {title}.', 'body': '{user} ({player}) has watched {title}.',
'icon': 'fa-eye' 'icon': 'fa-eye',
'media_types': ('movie', 'episode', 'track')
}, },
{'label': 'Buffer Warning', {'label': 'Buffer Warning',
'name': 'on_buffer', 'name': 'on_buffer',
'description': 'Trigger a notification when a stream exceeds the specified buffer threshold.', 'description': 'Trigger a notification when a stream exceeds the specified buffer threshold.',
'subject': 'PlexPy ({server_name})', 'subject': 'PlexPy ({server_name})',
'body': '{user} ({player}) is buffering {title}.', 'body': '{user} ({player}) is buffering {title}.',
'icon': 'fa-spinner' 'icon': 'fa-spinner',
'media_types': ('movie', 'episode', 'track')
}, },
{'label': 'User Concurrent Streams', {'label': 'User Concurrent Streams',
'name': 'on_concurrent', 'name': 'on_concurrent',
'description': 'Trigger a notification when a user exceeds the concurrent stream threshold.', 'description': 'Trigger a notification when a user exceeds the concurrent stream threshold.',
'subject': 'PlexPy ({server_name})', 'subject': 'PlexPy ({server_name})',
'body': '{user} has {user_streams} concurrent streams.', 'body': '{user} has {user_streams} concurrent streams.',
'icon': 'fa-arrow-circle-o-right' 'icon': 'fa-arrow-circle-o-right',
'media_types': ('movie', 'episode', 'track')
}, },
{'label': 'User New Device', {'label': 'User New Device',
'name': 'on_newdevice', 'name': 'on_newdevice',
'description': 'Trigger a notification when a user streams from a new device.', 'description': 'Trigger a notification when a user streams from a new device.',
'subject': 'PlexPy ({server_name})', 'subject': 'PlexPy ({server_name})',
'body': '{user} is streaming from a new device: {player}.', 'body': '{user} is streaming from a new device: {player}.',
'icon': 'fa-desktop' 'icon': 'fa-desktop',
'media_types': ('movie', 'episode', 'track')
}, },
{'label': 'Recently Added', {'label': 'Recently Added',
'name': 'on_created', 'name': 'on_created',
'description': 'Trigger a notification when a media item is added to the Plex Media Server.', 'description': 'Trigger a notification when a media item is added to the Plex Media Server.',
'subject': 'PlexPy ({server_name})', 'subject': 'PlexPy ({server_name})',
'body': '{title} was recently added to Plex.', 'body': '{title} was recently added to Plex.',
'icon': 'fa-download' 'icon': 'fa-download',
'media_types': ('movie', 'show', 'season', 'episode', 'artist', 'album', 'track')
}, },
{'label': 'Plex Server Down', {'label': 'Plex Server Down',
'name': 'on_intdown', 'name': 'on_intdown',
'description': 'Trigger a notification when the Plex Media Server cannot be reached internally.', 'description': 'Trigger a notification when the Plex Media Server cannot be reached internally.',
'subject': 'PlexPy ({server_name})', 'subject': 'PlexPy ({server_name})',
'body': 'The Plex Media Server is down.', 'body': 'The Plex Media Server is down.',
'icon': 'fa-server' 'icon': 'fa-server',
'media_types': ('server',)
}, },
{'label': 'Plex Server Back Up', {'label': 'Plex Server Back Up',
'name': 'on_intup', 'name': 'on_intup',
'description': 'Trigger a notification when the Plex Media Server can be reached internally after being down.', 'description': 'Trigger a notification when the Plex Media Server can be reached internally after being down.',
'subject': 'PlexPy ({server_name})', 'subject': 'PlexPy ({server_name})',
'body': 'The Plex Media Server is back up.', 'body': 'The Plex Media Server is back up.',
'icon': 'fa-server' 'icon': 'fa-server',
'media_types': ('server',)
}, },
{'label': 'Plex Remote Access Down', {'label': 'Plex Remote Access Down',
'name': 'on_extdown', 'name': 'on_extdown',
'description': 'Trigger a notification when the Plex Media Server cannot be reached externally.', 'description': 'Trigger a notification when the Plex Media Server cannot be reached externally.',
'subject': 'PlexPy ({server_name})', 'subject': 'PlexPy ({server_name})',
'body': 'The Plex Media Server remote access is down.', 'body': 'The Plex Media Server remote access is down.',
'icon': 'fa-server' 'icon': 'fa-server',
'media_types': ('server',)
}, },
{'label': 'Plex Remote Access Back Up', {'label': 'Plex Remote Access Back Up',
'name': 'on_extup', 'name': 'on_extup',
'description': 'Trigger a notification when the Plex Media Server can be reached externally after being down.', 'description': 'Trigger a notification when the Plex Media Server can be reached externally after being down.',
'subject': 'PlexPy ({server_name})', 'subject': 'PlexPy ({server_name})',
'body': 'The Plex Media Server remote access is back up.', 'body': 'The Plex Media Server remote access is back up.',
'icon': 'fa-server' 'icon': 'fa-server',
'media_types': ('server',)
}, },
{'label': 'Plex Update Available', {'label': 'Plex Update Available',
'name': 'on_pmsupdate', 'name': 'on_pmsupdate',
'description': 'Trigger a notification when an update for the Plex Media Server is available.', 'description': 'Trigger a notification when an update for the Plex Media Server is available.',
'subject': 'PlexPy ({server_name})', 'subject': 'PlexPy ({server_name})',
'body': 'An update is available for the Plex Media Server (version {update_version}).', 'body': 'An update is available for the Plex Media Server (version {update_version}).',
'icon': 'fa-refresh' 'icon': 'fa-refresh',
'media_types': ('server',)
}, },
{'label': 'PlexPy Update Available', {'label': 'PlexPy Update Available',
'name': 'on_plexpyupdate', 'name': 'on_plexpyupdate',
'description': 'Trigger a notification when an update for the PlexPy is available.', 'description': 'Trigger a notification when an update for the PlexPy is available.',
'subject': 'PlexPy ({server_name})', 'subject': 'PlexPy ({server_name})',
'body': 'An update is available for PlexPy (version {plexpy_update_version}).', 'body': 'An update is available for PlexPy (version {plexpy_update_version}).',
'icon': 'fa-refresh' 'icon': 'fa-refresh',
'media_types': ('server',)
} }
] ]

View file

@ -2993,8 +2993,10 @@ class WebInterface(object):
agent_id = int(agent_id) agent_id = int(agent_id)
text = [] text = []
media_types = next((a['media_types'] for a in notifiers.available_notification_actions()
if a['name'] == notify_action), ())
for media_type in ('movie', 'show', 'season', 'episode', 'artist', 'album', 'track'): for media_type in media_types:
test_subject, test_body = notification_handler.build_notify_text(subject=subject, test_subject, test_body = notification_handler.build_notify_text(subject=subject,
body=body, body=body,
notify_action=notify_action, notify_action=notify_action,