%def>
<%def name="javascriptIncludes()">
@@ -562,12 +606,28 @@ DOCUMENTATION :: END
});
});
+ // Send recently added notification
$('#send-recently-added-notification').on('click', function () {
- var full_title = $(this).data('title');
- var msg = 'Are you sure you want to send a recently added notification for the following?
' + full_title + '';
- var url = 'send_manual_on_created';
- var data = { rating_key: $(this).data('id') }
- confirmAjaxCall(url, msg, data, false);
+ var rating_key = $(this).data('id');
+
+ $('#send-recently-added-modal').modal();
+ $('#send-recently-added-modal').one('click', '#confirm-send-notification', function () {
+ $.ajax({
+ url: 'send_manual_on_created',
+ data: {
+ rating_key: rating_key,
+ notifier_id: $('#send-notification-notifier option:selected').val()
+ },
+ async: true,
+ success: function (data) {
+ if (data.result === 'success') {
+ showMsg(' ' + data.message, false, true, 5000);
+ } else {
+ showMsg(' ' + data.message, false, true, 5000, true);
+ }
+ }
+ });
+ });
});
% if data['media_type'] in ('show', 'season', 'artist', 'album'):
diff --git a/plexpy/notification_handler.py b/plexpy/notification_handler.py
index 748ac1ee..64235315 100644
--- a/plexpy/notification_handler.py
+++ b/plexpy/notification_handler.py
@@ -48,7 +48,7 @@ def process_queue():
break
elif params:
try:
- if 'notifier_id' in params:
+ if 'notify' in params:
notify(**params)
else:
add_notifier_each(**params)
@@ -68,13 +68,17 @@ def start_threads(num_threads=1):
thread.start()
-def add_notifier_each(notify_action=None, stream_data=None, timeline_data=None, manual_trigger=False, **kwargs):
+def add_notifier_each(notifier_id=None, notify_action=None, stream_data=None, timeline_data=None, manual_trigger=False, **kwargs):
if not notify_action:
logger.debug(u"PlexPy NotificationHandler :: Notify called but no action received.")
return
- # Check if any notification agents have notifications enabled for the action
- notifiers_enabled = notifiers.get_notifiers(notify_action=notify_action)
+ if notifier_id:
+ # Send to a specific notifier regardless if it is enabled
+ notifiers_enabled = notifiers.get_notifiers(notifier_id=notifier_id)
+ else:
+ # Check if any notification agents have notifications enabled for the action
+ notifiers_enabled = notifiers.get_notifiers(notify_action=notify_action)
# Check on_watched for each notifier
if notifiers_enabled and notify_action == 'on_watched':
@@ -84,14 +88,13 @@ def add_notifier_each(notify_action=None, stream_data=None, timeline_data=None,
# Already notified on_watched, remove from notifier
notifiers_enabled.pop(n)
- if notifiers_enabled:
+ if notifiers_enabled and not manual_trigger:
# Check if notification conditions are satisfied
- conditions = manual_trigger or \
- notify_conditions(notify_action=notify_action,
- stream_data=stream_data,
- timeline_data=timeline_data)
+ conditions = notify_conditions(notify_action=notify_action,
+ stream_data=stream_data,
+ timeline_data=timeline_data)
- if notifiers_enabled and conditions:
+ if notifiers_enabled and (manual_trigger or conditions):
if stream_data or timeline_data:
# Build the notification parameters
parameters = build_media_notify_params(notify_action=notify_action,
@@ -112,7 +115,8 @@ def add_notifier_each(notify_action=None, stream_data=None, timeline_data=None,
# Check custom user conditions
if manual_trigger or notify_custom_conditions(notifier_id=notifier['id'], parameters=parameters):
# Add each notifier to the queue
- data = {'notifier_id': notifier['id'],
+ data = {'notify': True,
+ 'notifier_id': notifier['id'],
'notify_action': notify_action,
'stream_data': stream_data,
'timeline_data': timeline_data,
@@ -1005,11 +1009,12 @@ def get_poster_info(poster_thumb, poster_key, poster_title):
# Upload poster_thumb to Imgur and get link
poster_url = helpers.uploadToImgur(poster_file, poster_title)
- # Create poster info
- poster_info = {'poster_title': poster_title, 'poster_url': poster_url}
+ if poster_url:
+ # Create poster info
+ poster_info = {'poster_title': poster_title, 'poster_url': poster_url}
- # Save the poster url in the database
- data_factory.set_poster_url(rating_key=poster_key, poster_title=poster_title, poster_url=poster_url)
+ # Save the poster url in the database
+ data_factory.set_poster_url(rating_key=poster_key, poster_title=poster_title, poster_url=poster_url)
# Delete the cached poster
os.remove(poster_file)
diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py
index fdcc9ce2..04716d0b 100644
--- a/plexpy/notifiers.py
+++ b/plexpy/notifiers.py
@@ -396,7 +396,7 @@ def get_notifiers(notifier_id=None, notify_action=None):
if notifier_id or notify_action:
where = 'WHERE '
if notifier_id:
- where_id += 'notifier_id = ?'
+ where_id += 'id = ?'
args.append(notifier_id)
if notify_action and notify_action in notify_actions:
where_action = '%s = ?' % notify_action
diff --git a/plexpy/webserve.py b/plexpy/webserve.py
index 31408b87..7a635afe 100644
--- a/plexpy/webserve.py
+++ b/plexpy/webserve.py
@@ -3091,28 +3091,9 @@ class WebInterface(object):
```
Required parameters:
- agent_id(str): The id of the notification agent to use
- 9 # Boxcar2
- 17 # Browser
- 10 # Email
- 16 # Facebook
- 0 # Growl
- 19 # Hipchat
- 12 # IFTTT
- 18 # Join
- 4 # NotifyMyAndroid
- 3 # Plex Home Theater
- 1 # Prowl
- 5 # Pushalot
- 6 # Pushbullet
- 7 # Pushover
- 15 # Scripts
- 14 # Slack
- 13 # Telegram
- 11 # Twitter
- 2 # XBMC
- subject(str): The subject of the message
- body(str): The body of the message
+ notifier_id (int): The ID number of the notification agent
+ subject (str): The subject of the message
+ body (str): The body of the message
Optional parameters:
None
@@ -3594,7 +3575,25 @@ class WebInterface(object):
@cherrypy.expose
@cherrypy.tools.json_out()
@requireAuth()
- def send_manual_on_created(self, rating_key='', **kwargs):
+ @addtoapi('notify_recently_added')
+ def send_manual_on_created(self, notifier_id='', rating_key='', **kwargs):
+ """ Send a recently added notification using PlexPy.
+
+ ```
+ Required parameters:
+ rating_key (int): The rating key for the media
+
+ Optional parameters:
+ notifier_id (int): The ID number of the notification agent.
+ The notification will send to all enabled notification agents if notifier id is not provided.
+
+ Returns:
+ json
+ {"result": "success",
+ "message": "Notification queued."
+ }
+ ```
+ """
if rating_key:
pms_connect = pmsconnect.PmsConnect()
metadata = pms_connect.get_metadata_details(rating_key=rating_key)
@@ -3605,6 +3604,9 @@ class WebInterface(object):
child_keys = [child['rating_key'] for child in children['children_list'] if child['rating_key']]
data['child_keys'] = child_keys
+ if notifier_id:
+ data['notifier_id'] = notifier_id
+
plexpy.NOTIFY_QUEUE.put(data)
return {'result': 'success', 'message': 'Notification queued.'}