mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 07:46:07 -07:00
Select notification agent for manual recently aded notifications
* And add to API
This commit is contained in:
parent
a17c3f8138
commit
5d2f1d7014
4 changed files with 121 additions and 54 deletions
|
@ -38,7 +38,7 @@ DOCUMENTATION :: END
|
|||
<%!
|
||||
import re
|
||||
|
||||
from plexpy import common
|
||||
from plexpy import common, notifiers
|
||||
|
||||
# Get audio codec file
|
||||
def af(codec):
|
||||
|
@ -386,16 +386,8 @@ DOCUMENTATION :: END
|
|||
</div>
|
||||
% endif
|
||||
<div class="btn-group">
|
||||
<%
|
||||
if data['media_type'] in ('movie', 'show', 'artist'):
|
||||
full_title = data['title']
|
||||
elif data['media_type'] in ('season', 'album'):
|
||||
full_title = data['parent_title'] + ' - ' + data['title']
|
||||
else:
|
||||
full_title = data['grandparent_title'] + ' - ' + data['title']
|
||||
%>
|
||||
<button class="btn btn-dark" data-toggle="button" aria-pressed="false" autocomplete="off" id="send-recently-added-notification"
|
||||
data-id="${data['rating_key']}" data-title="${full_title}">
|
||||
data-id="${data['rating_key']}">
|
||||
<i class="fa fa-bell"></i> Recently Added Notification
|
||||
</button>
|
||||
</div>
|
||||
|
@ -455,6 +447,58 @@ DOCUMENTATION :: END
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="send-recently-added-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="send-recently-added-modal">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-remove"></i></button>
|
||||
<h4 class="modal-title">Recently Added Notification</h4>
|
||||
</div>
|
||||
<div class="modal-body" style="text-align: center;">
|
||||
<p>Send a recently added notification for the following:</p>
|
||||
<p>
|
||||
<strong>
|
||||
% if data['media_type'] == 'movie':
|
||||
${data['title']}<br />${data['year']}
|
||||
% elif data['media_type'] == 'show':
|
||||
${data['title']}
|
||||
% elif data['media_type'] == 'season':
|
||||
${data['parent_title']}<br />S${data['media_index']}
|
||||
% elif data['media_type'] == 'episode':
|
||||
${data['grandparent_title']}<br />${data['title']}<br />S${data['parent_media_index']} · E${data['media_index']}
|
||||
% elif data['media_type'] == 'artist':
|
||||
${data['title']}
|
||||
% elif data['media_type'] == 'album':
|
||||
${data['parent_title']}<br />${data['title']}
|
||||
% elif data['media_type'] == 'track':
|
||||
${data['grandparent_title']}<br />${data['title']}<br />${data['parent_title']}
|
||||
% endif
|
||||
</strong>
|
||||
</p>
|
||||
<br />
|
||||
<label for="send-notification-notifier">Select the Notification Agent</label>
|
||||
<div class="row">
|
||||
<div class="col-md-8" style="float: none; margin: 0 auto;">
|
||||
<select class="form-control" id="send-notification-notifier" name="send-notification-notifier" value="" placeholder="The server owner has ended the stream." style="text-align: center;">
|
||||
<option value="">All Enabled Recently Added Notification Agents</option>
|
||||
% for notifier in sorted(notifiers.get_notifiers(), key=lambda k: (k['agent_label'], k['friendly_name'], k['id'])):
|
||||
% if notifier['friendly_name']:
|
||||
<option value="${notifier['id']}"> ${notifier['agent_label']} (${notifier['id']} - ${notifier['friendly_name']})</option>
|
||||
% else:
|
||||
<option value="${notifier['id']}"> ${notifier['agent_label']} (${notifier['id']})</option>
|
||||
% endif
|
||||
% endfor
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-dark" data-dismiss="modal">Cancel</button>
|
||||
<button type="button" class="btn btn-bright btn-ok" data-dismiss="modal" id="confirm-send-notification">Send</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</%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?<br><br><strong>' + full_title + '</strong>';
|
||||
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('<i class="fa fa-check"></i> ' + data.message, false, true, 5000);
|
||||
} else {
|
||||
showMsg('<i class="fa fa-exclamation-circle"></i> ' + data.message, false, true, 5000, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
% if data['media_type'] in ('show', 'season', 'artist', 'album'):
|
||||
|
|
|
@ -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,11 +68,15 @@ 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
|
||||
|
||||
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)
|
||||
|
||||
|
@ -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,
|
||||
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,6 +1009,7 @@ 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)
|
||||
|
||||
if poster_url:
|
||||
# Create poster info
|
||||
poster_info = {'poster_title': poster_title, 'poster_url': poster_url}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.'}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue