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
|
import re
|
||||||
|
|
||||||
from plexpy import common
|
from plexpy import common, notifiers
|
||||||
|
|
||||||
# Get audio codec file
|
# Get audio codec file
|
||||||
def af(codec):
|
def af(codec):
|
||||||
|
@ -386,16 +386,8 @@ DOCUMENTATION :: END
|
||||||
</div>
|
</div>
|
||||||
% endif
|
% endif
|
||||||
<div class="btn-group">
|
<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"
|
<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
|
<i class="fa fa-bell"></i> Recently Added Notification
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -455,6 +447,58 @@ DOCUMENTATION :: END
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</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>
|
||||||
|
|
||||||
<%def name="javascriptIncludes()">
|
<%def name="javascriptIncludes()">
|
||||||
|
@ -562,12 +606,28 @@ DOCUMENTATION :: END
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Send recently added notification
|
||||||
$('#send-recently-added-notification').on('click', function () {
|
$('#send-recently-added-notification').on('click', function () {
|
||||||
var full_title = $(this).data('title');
|
var rating_key = $(this).data('id');
|
||||||
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';
|
$('#send-recently-added-modal').modal();
|
||||||
var data = { rating_key: $(this).data('id') }
|
$('#send-recently-added-modal').one('click', '#confirm-send-notification', function () {
|
||||||
confirmAjaxCall(url, msg, data, false);
|
$.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>
|
</script>
|
||||||
% if data['media_type'] in ('show', 'season', 'artist', 'album'):
|
% if data['media_type'] in ('show', 'season', 'artist', 'album'):
|
||||||
|
|
|
@ -48,7 +48,7 @@ def process_queue():
|
||||||
break
|
break
|
||||||
elif params:
|
elif params:
|
||||||
try:
|
try:
|
||||||
if 'notifier_id' in params:
|
if 'notify' in params:
|
||||||
notify(**params)
|
notify(**params)
|
||||||
else:
|
else:
|
||||||
add_notifier_each(**params)
|
add_notifier_each(**params)
|
||||||
|
@ -68,13 +68,17 @@ def start_threads(num_threads=1):
|
||||||
thread.start()
|
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:
|
if not notify_action:
|
||||||
logger.debug(u"PlexPy NotificationHandler :: Notify called but no action received.")
|
logger.debug(u"PlexPy NotificationHandler :: Notify called but no action received.")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Check if any notification agents have notifications enabled for the action
|
if notifier_id:
|
||||||
notifiers_enabled = notifiers.get_notifiers(notify_action=notify_action)
|
# 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
|
# Check on_watched for each notifier
|
||||||
if notifiers_enabled and notify_action == 'on_watched':
|
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
|
# Already notified on_watched, remove from notifier
|
||||||
notifiers_enabled.pop(n)
|
notifiers_enabled.pop(n)
|
||||||
|
|
||||||
if notifiers_enabled:
|
if notifiers_enabled and not manual_trigger:
|
||||||
# Check if notification conditions are satisfied
|
# Check if notification conditions are satisfied
|
||||||
conditions = manual_trigger or \
|
conditions = notify_conditions(notify_action=notify_action,
|
||||||
notify_conditions(notify_action=notify_action,
|
stream_data=stream_data,
|
||||||
stream_data=stream_data,
|
timeline_data=timeline_data)
|
||||||
timeline_data=timeline_data)
|
|
||||||
|
|
||||||
if notifiers_enabled and conditions:
|
if notifiers_enabled and (manual_trigger or conditions):
|
||||||
if stream_data or timeline_data:
|
if stream_data or timeline_data:
|
||||||
# Build the notification parameters
|
# Build the notification parameters
|
||||||
parameters = build_media_notify_params(notify_action=notify_action,
|
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
|
# Check custom user conditions
|
||||||
if manual_trigger or notify_custom_conditions(notifier_id=notifier['id'], parameters=parameters):
|
if manual_trigger or notify_custom_conditions(notifier_id=notifier['id'], parameters=parameters):
|
||||||
# Add each notifier to the queue
|
# Add each notifier to the queue
|
||||||
data = {'notifier_id': notifier['id'],
|
data = {'notify': True,
|
||||||
|
'notifier_id': notifier['id'],
|
||||||
'notify_action': notify_action,
|
'notify_action': notify_action,
|
||||||
'stream_data': stream_data,
|
'stream_data': stream_data,
|
||||||
'timeline_data': timeline_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
|
# Upload poster_thumb to Imgur and get link
|
||||||
poster_url = helpers.uploadToImgur(poster_file, poster_title)
|
poster_url = helpers.uploadToImgur(poster_file, poster_title)
|
||||||
|
|
||||||
# Create poster info
|
if poster_url:
|
||||||
poster_info = {'poster_title': poster_title, 'poster_url': poster_url}
|
# Create poster info
|
||||||
|
poster_info = {'poster_title': poster_title, 'poster_url': poster_url}
|
||||||
|
|
||||||
# Save the poster url in the database
|
# Save the poster url in the database
|
||||||
data_factory.set_poster_url(rating_key=poster_key, poster_title=poster_title, poster_url=poster_url)
|
data_factory.set_poster_url(rating_key=poster_key, poster_title=poster_title, poster_url=poster_url)
|
||||||
|
|
||||||
# Delete the cached poster
|
# Delete the cached poster
|
||||||
os.remove(poster_file)
|
os.remove(poster_file)
|
||||||
|
|
|
@ -396,7 +396,7 @@ def get_notifiers(notifier_id=None, notify_action=None):
|
||||||
if notifier_id or notify_action:
|
if notifier_id or notify_action:
|
||||||
where = 'WHERE '
|
where = 'WHERE '
|
||||||
if notifier_id:
|
if notifier_id:
|
||||||
where_id += 'notifier_id = ?'
|
where_id += 'id = ?'
|
||||||
args.append(notifier_id)
|
args.append(notifier_id)
|
||||||
if notify_action and notify_action in notify_actions:
|
if notify_action and notify_action in notify_actions:
|
||||||
where_action = '%s = ?' % notify_action
|
where_action = '%s = ?' % notify_action
|
||||||
|
|
|
@ -3091,28 +3091,9 @@ class WebInterface(object):
|
||||||
|
|
||||||
```
|
```
|
||||||
Required parameters:
|
Required parameters:
|
||||||
agent_id(str): The id of the notification agent to use
|
notifier_id (int): The ID number of the notification agent
|
||||||
9 # Boxcar2
|
subject (str): The subject of the message
|
||||||
17 # Browser
|
body (str): The body of the message
|
||||||
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
|
|
||||||
|
|
||||||
Optional parameters:
|
Optional parameters:
|
||||||
None
|
None
|
||||||
|
@ -3594,7 +3575,25 @@ class WebInterface(object):
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
@cherrypy.tools.json_out()
|
@cherrypy.tools.json_out()
|
||||||
@requireAuth()
|
@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:
|
if rating_key:
|
||||||
pms_connect = pmsconnect.PmsConnect()
|
pms_connect = pmsconnect.PmsConnect()
|
||||||
metadata = pms_connect.get_metadata_details(rating_key=rating_key)
|
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']]
|
child_keys = [child['rating_key'] for child in children['children_list'] if child['rating_key']]
|
||||||
data['child_keys'] = child_keys
|
data['child_keys'] = child_keys
|
||||||
|
|
||||||
|
if notifier_id:
|
||||||
|
data['notifier_id'] = notifier_id
|
||||||
|
|
||||||
plexpy.NOTIFY_QUEUE.put(data)
|
plexpy.NOTIFY_QUEUE.put(data)
|
||||||
return {'result': 'success', 'message': 'Notification queued.'}
|
return {'result': 'success', 'message': 'Notification queued.'}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue