mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 07:46:07 -07:00
fix conflicts
This commit is contained in:
parent
b490831a50
commit
ad365c7dd0
5 changed files with 361 additions and 44 deletions
|
@ -751,6 +751,22 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<ul id="accordion-scripts" class="accordion list-unstyled">
|
||||||
|
<li>
|
||||||
|
<div class="link"><i class="glyphicon glyphicon-console"></i> Script <i class="fa fa-chevron-down"></i></div>
|
||||||
|
<ul class="submenu">
|
||||||
|
<li>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="notify_scripts_args_text">Script arguments</label>
|
||||||
|
<input class="form-control" type="text" id="notify_scripts_args_text" name="notify_scripts_args_text" value="${config['notify_scripts_args_text']}" data-parsley-trigger="change" required>
|
||||||
|
<p class="help-block">Set arguments passed to the script</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
<p><input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully"></p>
|
<p><input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully"></p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1575,6 +1591,7 @@ $(document).ready(function() {
|
||||||
|
|
||||||
var accordion_session = new Accordion($('#accordion-session'), false);
|
var accordion_session = new Accordion($('#accordion-session'), false);
|
||||||
var accordion_timeline = new Accordion($('#accordion-timeline'), false);
|
var accordion_timeline = new Accordion($('#accordion-timeline'), false);
|
||||||
|
var accordion_scripts = new Accordion($('#accordion-scripts'), false);
|
||||||
|
|
||||||
var cards = "${config['home_stats_cards']}".split(/[\s,]+/);
|
var cards = "${config['home_stats_cards']}".split(/[\s,]+/);
|
||||||
cards.forEach(function (item) {
|
cards.forEach(function (item) {
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
import plexpy.logger
|
import plexpy.logger
|
||||||
import itertools
|
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
from configobj import ConfigObj
|
from configobj import ConfigObj
|
||||||
|
|
||||||
|
@ -14,8 +12,6 @@ def bool_int(value):
|
||||||
value = 0
|
value = 0
|
||||||
return int(bool(value))
|
return int(bool(value))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_CONFIG_DEFINITIONS = {
|
_CONFIG_DEFINITIONS = {
|
||||||
'DATE_FORMAT': (str, 'General', 'YYYY-MM-DD'),
|
'DATE_FORMAT': (str, 'General', 'YYYY-MM-DD'),
|
||||||
'GROUPING_GLOBAL_HISTORY': (int, 'PlexWatch', 0),
|
'GROUPING_GLOBAL_HISTORY': (int, 'PlexWatch', 0),
|
||||||
|
@ -194,6 +190,7 @@ _CONFIG_DEFINITIONS = {
|
||||||
'NOTIFY_ON_EXTUP_BODY_TEXT': (unicode, 'Monitoring', 'The Plex Media Server remote access is back up.'),
|
'NOTIFY_ON_EXTUP_BODY_TEXT': (unicode, 'Monitoring', 'The Plex Media Server remote access is back up.'),
|
||||||
'NOTIFY_ON_INTUP_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
|
'NOTIFY_ON_INTUP_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
|
||||||
'NOTIFY_ON_INTUP_BODY_TEXT': (unicode, 'Monitoring', 'The Plex Media Server is back up.'),
|
'NOTIFY_ON_INTUP_BODY_TEXT': (unicode, 'Monitoring', 'The Plex Media Server is back up.'),
|
||||||
|
'NOTIFY_SCRIPTS_ARGS_TEXT': (unicode, 'Monitoring', ''),
|
||||||
'OSX_NOTIFY_APP': (str, 'OSX_Notify', '/Applications/PlexPy'),
|
'OSX_NOTIFY_APP': (str, 'OSX_Notify', '/Applications/PlexPy'),
|
||||||
'OSX_NOTIFY_ENABLED': (int, 'OSX_Notify', 0),
|
'OSX_NOTIFY_ENABLED': (int, 'OSX_Notify', 0),
|
||||||
'OSX_NOTIFY_ON_PLAY': (int, 'OSX_Notify', 0),
|
'OSX_NOTIFY_ON_PLAY': (int, 'OSX_Notify', 0),
|
||||||
|
@ -298,6 +295,30 @@ _CONFIG_DEFINITIONS = {
|
||||||
'SLACK_ON_INTDOWN': (int, 'Slack', 0),
|
'SLACK_ON_INTDOWN': (int, 'Slack', 0),
|
||||||
'SLACK_ON_EXTUP': (int, 'Slack', 0),
|
'SLACK_ON_EXTUP': (int, 'Slack', 0),
|
||||||
'SLACK_ON_INTUP': (int, 'Slack', 0),
|
'SLACK_ON_INTUP': (int, 'Slack', 0),
|
||||||
|
'SCRIPTS_ENABLED': (str, 'Scripts', 0),
|
||||||
|
'SCRIPTS_FOLDER': (str, 'Scripts', ''),
|
||||||
|
'SCRIPTS_ON_PLAY': (int, 'Scripts', 0),
|
||||||
|
'SCRIPTS_ON_STOP': (int, 'Scripts', 0),
|
||||||
|
'SCRIPTS_ON_PAUSE': (int, 'Scripts', 0),
|
||||||
|
'SCRIPTS_ON_RESUME': (int, 'Scripts', 0),
|
||||||
|
'SCRIPTS_ON_BUFFER': (int, 'Scripts', 0),
|
||||||
|
'SCRIPTS_ON_WATCHED': (int, 'Scripts', 0),
|
||||||
|
'SCRIPTS_ON_CREATED': (int, 'Scripts', 0),
|
||||||
|
'SCRIPTS_ON_EXTDOWN': (int, 'Scripts', 0),
|
||||||
|
'SCRIPTS_ON_EXTUP': (int, 'Scripts', 0),
|
||||||
|
'SCRIPTS_ON_INTDOWN': (int, 'Scripts', 0),
|
||||||
|
'SCRIPTS_ON_INTUP': (int, 'Scripts', 0),
|
||||||
|
'SCRIPTS_ON_PLAY_SCRIPT': (str, 'Scripts', ''),
|
||||||
|
'SCRIPTS_ON_STOP_SCRIPT': (str, 'Scripts', ''),
|
||||||
|
'SCRIPTS_ON_PAUSE_SCRIPT': (str, 'Scripts', ''),
|
||||||
|
'SCRIPTS_ON_RESUME_SCRIPT': (str, 'Scripts', ''),
|
||||||
|
'SCRIPTS_ON_BUFFER_SCRIPT': (str, 'Scripts', ''),
|
||||||
|
'SCRIPTS_ON_WATCHED_SCRIPT': (str, 'Scripts', ''),
|
||||||
|
'SCRIPTS_ON_CREATED_SCRIPT': (str, 'Scripts', ''),
|
||||||
|
'SCRIPTS_ON_EXTDOWN_SCRIPT': (str, 'Scripts', ''),
|
||||||
|
'SCRIPTS_ON_EXTUP_SCRIPT': (str, 'Scripts', ''),
|
||||||
|
'SCRIPTS_ON_INTDOWN_SCRIPT': (str, 'Scripts', ''),
|
||||||
|
'SCRIPTS_ON_INTUP_SCRIPT': (str, 'Scripts', ''),
|
||||||
'TELEGRAM_BOT_TOKEN': (str, 'Telegram', ''),
|
'TELEGRAM_BOT_TOKEN': (str, 'Telegram', ''),
|
||||||
'TELEGRAM_ENABLED': (int, 'Telegram', 0),
|
'TELEGRAM_ENABLED': (int, 'Telegram', 0),
|
||||||
'TELEGRAM_CHAT_ID': (str, 'Telegram', ''),
|
'TELEGRAM_CHAT_ID': (str, 'Telegram', ''),
|
||||||
|
@ -351,6 +372,8 @@ _CONFIG_DEFINITIONS = {
|
||||||
'XBMC_ON_EXTUP': (int, 'XBMC', 0),
|
'XBMC_ON_EXTUP': (int, 'XBMC', 0),
|
||||||
'XBMC_ON_INTUP': (int, 'XBMC', 0)
|
'XBMC_ON_INTUP': (int, 'XBMC', 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# pylint:disable=R0902
|
# pylint:disable=R0902
|
||||||
# it might be nice to refactor for fewer instance variables
|
# it might be nice to refactor for fewer instance variables
|
||||||
class Config(object):
|
class Config(object):
|
||||||
|
|
|
@ -41,7 +41,10 @@ def notify(stream_data=None, notify_action=None):
|
||||||
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'],
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1],
|
||||||
|
notify_action=notify_action,
|
||||||
|
script_args=notify_strings[2])
|
||||||
|
|
||||||
# Set the notification state in the db
|
# Set the notification state in the db
|
||||||
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
|
@ -51,7 +54,9 @@ def notify(stream_data=None, notify_action=None):
|
||||||
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'],
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1],
|
||||||
|
notify_action=notify_action,
|
||||||
|
script_args=notify_strings[2])
|
||||||
|
|
||||||
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
|
@ -61,7 +66,9 @@ def notify(stream_data=None, notify_action=None):
|
||||||
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'],
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1],
|
||||||
|
notify_action=notify_action,
|
||||||
|
script_args=notify_strings[2])
|
||||||
|
|
||||||
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
|
@ -71,7 +78,9 @@ def notify(stream_data=None, notify_action=None):
|
||||||
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'],
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1],
|
||||||
|
notify_action=notify_action,
|
||||||
|
script_args=notify_strings[2])
|
||||||
|
|
||||||
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
|
@ -80,7 +89,9 @@ def notify(stream_data=None, notify_action=None):
|
||||||
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'],
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1],
|
||||||
|
notify_action=notify_action,
|
||||||
|
script_args=notify_strings[2])
|
||||||
|
|
||||||
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
|
@ -94,7 +105,10 @@ def notify(stream_data=None, notify_action=None):
|
||||||
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'],
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1],
|
||||||
|
notify_action=notify_action,
|
||||||
|
script_args=notify_strings[2])
|
||||||
|
|
||||||
# Set the notification state in the db
|
# Set the notification state in the db
|
||||||
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
|
@ -106,7 +120,10 @@ def notify(stream_data=None, notify_action=None):
|
||||||
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'],
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1],
|
||||||
|
notify_action=notify_action,
|
||||||
|
script_args=notify_strings[2])
|
||||||
|
|
||||||
# Set the notification state in the db
|
# Set the notification state in the db
|
||||||
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
|
@ -118,7 +135,10 @@ def notify(stream_data=None, notify_action=None):
|
||||||
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'],
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1],
|
||||||
|
notify_action=notify_action,
|
||||||
|
script_args=notify_strings[2])
|
||||||
|
|
||||||
# Set the notification state in the db
|
# Set the notification state in the db
|
||||||
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
|
@ -127,7 +147,10 @@ def notify(stream_data=None, notify_action=None):
|
||||||
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'],
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1],
|
||||||
|
notify_action=notify_action,
|
||||||
|
script_args=notify_strings[2])
|
||||||
|
|
||||||
# Set the notification state in the db
|
# Set the notification state in the db
|
||||||
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
|
@ -136,7 +159,10 @@ def notify(stream_data=None, notify_action=None):
|
||||||
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'],
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1],
|
||||||
|
notify_action=notify_action,
|
||||||
|
script_args=notify_strings[2])
|
||||||
|
|
||||||
# Set the notification state in the db
|
# Set the notification state in the db
|
||||||
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
|
@ -145,7 +171,10 @@ def notify(stream_data=None, notify_action=None):
|
||||||
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'],
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1],
|
||||||
|
notify_action=notify_action,
|
||||||
|
script_args=notify_strings[2])
|
||||||
|
|
||||||
# Set the notification state in the db
|
# Set the notification state in the db
|
||||||
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
|
@ -154,7 +183,10 @@ def notify(stream_data=None, notify_action=None):
|
||||||
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'],
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1],
|
||||||
|
notify_action=notify_action,
|
||||||
|
script_args=notify_strings[2])
|
||||||
|
|
||||||
# Set the notification state in the db
|
# Set the notification state in the db
|
||||||
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
|
@ -521,6 +553,16 @@ def build_notify_text(session=None, timeline=None, state=None):
|
||||||
|
|
||||||
# Default subject text
|
# Default subject text
|
||||||
subject_text = 'PlexPy (%s)' % server_name
|
subject_text = 'PlexPy (%s)' % server_name
|
||||||
|
# Default scripts args
|
||||||
|
script_args = ''
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Add script arguments
|
||||||
|
script_args = unicode(plexpy.CONFIG.NOTIFY_SCRIPTS_ARGS_TEXT).format(**available_params)
|
||||||
|
except LookupError as e:
|
||||||
|
logger.error(u"PlexPy Notifier :: Unable to parse field %s in notification subject. Using fallback." % e)
|
||||||
|
except:
|
||||||
|
logger.error(u"PlexPy Notifier :: Unable to parse custom notification subject. Using fallback.")
|
||||||
|
|
||||||
if state == 'play':
|
if state == 'play':
|
||||||
# Default body text
|
# Default body text
|
||||||
|
@ -543,9 +585,9 @@ def build_notify_text(session=None, timeline=None, state=None):
|
||||||
except:
|
except:
|
||||||
logger.error(u"PlexPy Notifier :: Unable to parse custom notification body. Using fallback.")
|
logger.error(u"PlexPy Notifier :: Unable to parse custom notification body. Using fallback.")
|
||||||
|
|
||||||
return [subject_text, body_text]
|
return [subject_text, body_text, script_args]
|
||||||
else:
|
else:
|
||||||
return [subject_text, body_text]
|
return [subject_text, body_text, script_args]
|
||||||
elif state == 'stop':
|
elif state == 'stop':
|
||||||
# Default body text
|
# Default body text
|
||||||
body_text = '%s (%s) has stopped %s' % (session['friendly_name'],
|
body_text = '%s (%s) has stopped %s' % (session['friendly_name'],
|
||||||
|
@ -567,9 +609,9 @@ def build_notify_text(session=None, timeline=None, state=None):
|
||||||
except:
|
except:
|
||||||
logger.error(u"PlexPy Notifier :: Unable to parse custom notification body. Using fallback.")
|
logger.error(u"PlexPy Notifier :: Unable to parse custom notification body. Using fallback.")
|
||||||
|
|
||||||
return [subject_text, body_text]
|
return [subject_text, body_text, script_args]
|
||||||
else:
|
else:
|
||||||
return [subject_text, body_text]
|
return [subject_text, body_text, script_args]
|
||||||
elif state == 'pause':
|
elif state == 'pause':
|
||||||
# Default body text
|
# Default body text
|
||||||
body_text = '%s (%s) has paused %s' % (session['friendly_name'],
|
body_text = '%s (%s) has paused %s' % (session['friendly_name'],
|
||||||
|
@ -591,9 +633,9 @@ def build_notify_text(session=None, timeline=None, state=None):
|
||||||
except:
|
except:
|
||||||
logger.error(u"PlexPy Notifier :: Unable to parse custom notification body. Using fallback.")
|
logger.error(u"PlexPy Notifier :: Unable to parse custom notification body. Using fallback.")
|
||||||
|
|
||||||
return [subject_text, body_text]
|
return [subject_text, body_text, script_args]
|
||||||
else:
|
else:
|
||||||
return [subject_text, body_text]
|
return [subject_text, body_text, script_args]
|
||||||
elif state == 'resume':
|
elif state == 'resume':
|
||||||
# Default body text
|
# Default body text
|
||||||
body_text = '%s (%s) has resumed %s' % (session['friendly_name'],
|
body_text = '%s (%s) has resumed %s' % (session['friendly_name'],
|
||||||
|
@ -615,9 +657,9 @@ def build_notify_text(session=None, timeline=None, state=None):
|
||||||
except:
|
except:
|
||||||
logger.error(u"PlexPy Notifier :: Unable to parse custom notification body. Using fallback.")
|
logger.error(u"PlexPy Notifier :: Unable to parse custom notification body. Using fallback.")
|
||||||
|
|
||||||
return [subject_text, body_text]
|
return [subject_text, body_text, script_args]
|
||||||
else:
|
else:
|
||||||
return [subject_text, body_text]
|
return [subject_text, body_text, script_args]
|
||||||
elif state == 'buffer':
|
elif state == 'buffer':
|
||||||
# Default body text
|
# Default body text
|
||||||
body_text = '%s (%s) is buffering %s' % (session['friendly_name'],
|
body_text = '%s (%s) is buffering %s' % (session['friendly_name'],
|
||||||
|
@ -639,9 +681,9 @@ def build_notify_text(session=None, timeline=None, state=None):
|
||||||
except:
|
except:
|
||||||
logger.error(u"PlexPy Notifier :: Unable to parse custom notification body. Using fallback.")
|
logger.error(u"PlexPy Notifier :: Unable to parse custom notification body. Using fallback.")
|
||||||
|
|
||||||
return [subject_text, body_text]
|
return [subject_text, body_text, script_args]
|
||||||
else:
|
else:
|
||||||
return [subject_text, body_text]
|
return [subject_text, body_text, script_args]
|
||||||
elif state == 'watched':
|
elif state == 'watched':
|
||||||
# Default body text
|
# Default body text
|
||||||
body_text = '%s (%s) has watched %s' % (session['friendly_name'],
|
body_text = '%s (%s) has watched %s' % (session['friendly_name'],
|
||||||
|
@ -663,9 +705,9 @@ def build_notify_text(session=None, timeline=None, state=None):
|
||||||
except:
|
except:
|
||||||
logger.error(u"PlexPy Notifier :: Unable to parse custom notification body. Using fallback.")
|
logger.error(u"PlexPy Notifier :: Unable to parse custom notification body. Using fallback.")
|
||||||
|
|
||||||
return [subject_text, body_text]
|
return [subject_text, body_text, script_args]
|
||||||
else:
|
else:
|
||||||
return [subject_text, body_text]
|
return [subject_text, body_text, script_args]
|
||||||
elif state == 'created':
|
elif state == 'created':
|
||||||
# Default body text
|
# Default body text
|
||||||
body_text = '%s was recently added to Plex.' % full_title
|
body_text = '%s was recently added to Plex.' % full_title
|
||||||
|
@ -685,9 +727,9 @@ def build_notify_text(session=None, timeline=None, state=None):
|
||||||
except:
|
except:
|
||||||
logger.error(u"PlexPy Notifier :: Unable to parse custom notification body. Using fallback.")
|
logger.error(u"PlexPy Notifier :: Unable to parse custom notification body. Using fallback.")
|
||||||
|
|
||||||
return [subject_text, body_text]
|
return [subject_text, body_text, script_args]
|
||||||
else:
|
else:
|
||||||
return [subject_text, body_text]
|
return [subject_text, body_text, script_args]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -716,7 +758,8 @@ def build_server_notify_text(state=None):
|
||||||
on_intup_body = plexpy.CONFIG.NOTIFY_ON_INTUP_BODY_TEXT
|
on_intup_body = plexpy.CONFIG.NOTIFY_ON_INTUP_BODY_TEXT
|
||||||
|
|
||||||
available_params = {'server_name': server_name,
|
available_params = {'server_name': server_name,
|
||||||
'server_uptime': server_uptime}
|
'server_uptime': server_uptime,
|
||||||
|
'action': state}
|
||||||
|
|
||||||
# Default text
|
# Default text
|
||||||
subject_text = 'PlexPy (%s)' % server_name
|
subject_text = 'PlexPy (%s)' % server_name
|
||||||
|
|
|
@ -54,7 +54,9 @@ AGENT_IDS = {"Growl": 0,
|
||||||
"Twitter": 11,
|
"Twitter": 11,
|
||||||
"IFTTT": 12,
|
"IFTTT": 12,
|
||||||
"Telegram": 13,
|
"Telegram": 13,
|
||||||
"Slack":14}
|
"Slack": 14,
|
||||||
|
"Scripts": 15}
|
||||||
|
|
||||||
|
|
||||||
def available_notification_agents():
|
def available_notification_agents():
|
||||||
agents = [{'name': 'Growl',
|
agents = [{'name': 'Growl',
|
||||||
|
@ -294,7 +296,25 @@ def available_notification_agents():
|
||||||
'on_intdown': plexpy.CONFIG.SLACK_ON_INTDOWN,
|
'on_intdown': plexpy.CONFIG.SLACK_ON_INTDOWN,
|
||||||
'on_extup': plexpy.CONFIG.SLACK_ON_EXTUP,
|
'on_extup': plexpy.CONFIG.SLACK_ON_EXTUP,
|
||||||
'on_intup': plexpy.CONFIG.SLACK_ON_INTUP
|
'on_intup': plexpy.CONFIG.SLACK_ON_INTUP
|
||||||
|
},
|
||||||
|
{'name': 'Scripts',
|
||||||
|
'id': AGENT_IDS['Scripts'],
|
||||||
|
'config_prefix': 'scripts',
|
||||||
|
'has_config': True,
|
||||||
|
'state': checked(plexpy.CONFIG.SCRIPTS_ENABLED),
|
||||||
|
'on_play': plexpy.CONFIG.SCRIPTS_ON_PLAY,
|
||||||
|
'on_stop': plexpy.CONFIG.SCRIPTS_ON_STOP,
|
||||||
|
'on_pause': plexpy.CONFIG.SCRIPTS_ON_PAUSE,
|
||||||
|
'on_resume': plexpy.CONFIG.SCRIPTS_ON_RESUME,
|
||||||
|
'on_buffer': plexpy.CONFIG.SCRIPTS_ON_BUFFER,
|
||||||
|
'on_watched': plexpy.CONFIG.SCRIPTS_ON_WATCHED,
|
||||||
|
'on_created': plexpy.CONFIG.SCRIPTS_ON_CREATED,
|
||||||
|
'on_extdown': plexpy.CONFIG.SCRIPTS_ON_EXTDOWN,
|
||||||
|
'on_extup': plexpy.CONFIG.SCRIPTS_ON_EXTUP,
|
||||||
|
'on_intdown': plexpy.CONFIG.SCRIPTS_ON_INTDOWN,
|
||||||
|
'on_intup': plexpy.CONFIG.SCRIPTS_ON_INTUP
|
||||||
}
|
}
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# OSX Notifications should only be visible if it can be used
|
# OSX Notifications should only be visible if it can be used
|
||||||
|
@ -320,6 +340,7 @@ def available_notification_agents():
|
||||||
|
|
||||||
return agents
|
return agents
|
||||||
|
|
||||||
|
|
||||||
def get_notification_agent_config(config_id):
|
def get_notification_agent_config(config_id):
|
||||||
if config_id:
|
if config_id:
|
||||||
config_id = int(config_id)
|
config_id = int(config_id)
|
||||||
|
@ -369,12 +390,16 @@ def get_notification_agent_config(config_id):
|
||||||
elif config_id == 14:
|
elif config_id == 14:
|
||||||
slackClient = SLACK()
|
slackClient = SLACK()
|
||||||
return slackClient.return_config_options()
|
return slackClient.return_config_options()
|
||||||
|
elif config_id == 15:
|
||||||
|
script = Scripts()
|
||||||
|
return script.return_config_options()
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def send_notification(config_id, subject, body):
|
|
||||||
|
def send_notification(config_id, subject, body, notify_action=None):
|
||||||
if str(config_id).isdigit():
|
if str(config_id).isdigit():
|
||||||
config_id = int(config_id)
|
config_id = int(config_id)
|
||||||
|
|
||||||
|
@ -423,6 +448,9 @@ def send_notification(config_id, subject, body):
|
||||||
elif config_id == 14:
|
elif config_id == 14:
|
||||||
slackClient = SLACK()
|
slackClient = SLACK()
|
||||||
slackClient.notify(message=body, event=subject)
|
slackClient.notify(message=body, event=subject)
|
||||||
|
elif config_id == 15:
|
||||||
|
scripts = Scripts()
|
||||||
|
scripts.notify(message=body, subject=subject, notify_action=notify_action, script_args=script_args)
|
||||||
else:
|
else:
|
||||||
logger.debug(u"PlexPy Notifier :: Unknown agent id received.")
|
logger.debug(u"PlexPy Notifier :: Unknown agent id received.")
|
||||||
else:
|
else:
|
||||||
|
@ -685,6 +713,7 @@ class XBMC(object):
|
||||||
|
|
||||||
return config_option
|
return config_option
|
||||||
|
|
||||||
|
|
||||||
class Plex(object):
|
class Plex(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
|
@ -1676,3 +1705,201 @@ class SLACK(object):
|
||||||
]
|
]
|
||||||
|
|
||||||
return config_option
|
return config_option
|
||||||
|
|
||||||
|
|
||||||
|
class Scripts(object):
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def conf(self, options):
|
||||||
|
return cherrypy.config['config'].get('Scripts', options)
|
||||||
|
|
||||||
|
def updateLibrary(self):
|
||||||
|
# For uniformity reasons not removed
|
||||||
|
return
|
||||||
|
|
||||||
|
def test(self, subject, message, action):
|
||||||
|
self.notify(subject, message, action)
|
||||||
|
|
||||||
|
def list_scripts(self):
|
||||||
|
scriptdir = plexpy.CONFIG.SCRIPTS_FOLDER
|
||||||
|
scripts = {}
|
||||||
|
|
||||||
|
if scriptdir and not os.path.exists(scriptdir):
|
||||||
|
os.makedirs(scriptdir)
|
||||||
|
|
||||||
|
for root, dirs, files in os.walk(scriptdir):
|
||||||
|
for f in files:
|
||||||
|
name, ext = os.path.splitext(f)
|
||||||
|
ext = ext[1:]
|
||||||
|
if ext in ('rb', 'pl', 'bat', 'py', 'sh', 'cmd', 'php'):
|
||||||
|
fp = os.path.join(scriptdir, f)
|
||||||
|
scripts[fp] = fp
|
||||||
|
|
||||||
|
return scripts
|
||||||
|
|
||||||
|
def notify(self, subject, message, notify_action=None, script_args=''):
|
||||||
|
logger.debug('Ran notify script subject: %s message: %s, action: %s script_args: %s' % (subject, message, notify_action, script_args))
|
||||||
|
|
||||||
|
prefix = ''
|
||||||
|
script = ''
|
||||||
|
|
||||||
|
if not plexpy.CONFIG.SCRIPTS_FOLDER:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Make sure we use the correct script..
|
||||||
|
if notify_action == 'play':
|
||||||
|
script = plexpy.CONFIG.SCRIPTS_ON_PLAY_SCRIPT
|
||||||
|
|
||||||
|
elif notify_action == 'stop':
|
||||||
|
script = plexpy.CONFIG.SCRIPTS_ON_STOP_SCRIPT
|
||||||
|
|
||||||
|
elif notify_action == 'pause':
|
||||||
|
script = plexpy.CONFIG.SCRIPTS_ON_PAUSE_SCRIPT
|
||||||
|
|
||||||
|
elif notify_action == 'resume':
|
||||||
|
script = plexpy.CONFIG.SCRIPTS_ON_RESUME_SCRIPT
|
||||||
|
|
||||||
|
elif notify_action == 'buffer':
|
||||||
|
script = plexpy.CONFIG.SCRIPTS_ON_BUFFER_SCRIPT
|
||||||
|
|
||||||
|
elif notify_action == 'extdown':
|
||||||
|
script = plexpy.CONFIG.SCRIPTS_ON_EXTDOWN_SCRIPT
|
||||||
|
|
||||||
|
elif notify_action == 'extup':
|
||||||
|
script = plexpy.CONFIG.SCRIPTS_ON_EXTUP_SCRIPT
|
||||||
|
|
||||||
|
elif notify_action == 'intdown':
|
||||||
|
script = plexpy.CONFIG.SCRIPTS_ON_INTDOWN_SCRIPT
|
||||||
|
|
||||||
|
elif notify_action == 'intup':
|
||||||
|
script = plexpy.CONFIG.SCRIPTS_ON_INTUP_SCRIPT
|
||||||
|
|
||||||
|
elif notify_action == 'created':
|
||||||
|
script = plexpy.CONFIG.SCRIPTS_ON_CREATED_SCRIPT
|
||||||
|
|
||||||
|
name, ext = os.path.splitext(script)
|
||||||
|
|
||||||
|
if ext == '.py':
|
||||||
|
prefix = 'python'
|
||||||
|
elif ext == '.php':
|
||||||
|
prefix = 'php'
|
||||||
|
elif ext == '.pl':
|
||||||
|
prefix = 'perl'
|
||||||
|
elif ext == '.rb':
|
||||||
|
prefix = 'ruby'
|
||||||
|
|
||||||
|
script = script.split()
|
||||||
|
|
||||||
|
if prefix:
|
||||||
|
script.insert(0, prefix)
|
||||||
|
|
||||||
|
if script_args:
|
||||||
|
script = script + script_args.split()
|
||||||
|
|
||||||
|
try:
|
||||||
|
p = subprocess.Popen(script, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT, cwd=plexpy.CONFIG.SCRIPTS_FOLDER)
|
||||||
|
|
||||||
|
out, error = p.communicate()
|
||||||
|
status = p.returncode
|
||||||
|
|
||||||
|
if out and status:
|
||||||
|
out = out.strip()
|
||||||
|
logger.debug(u'%s returned %s' % (script, out))
|
||||||
|
|
||||||
|
if error:
|
||||||
|
error = error.strip()
|
||||||
|
logger.error(u'%s' % error)
|
||||||
|
|
||||||
|
except OSError as out:
|
||||||
|
logger.error(u'Failed to run %s error %s' % (script, out))
|
||||||
|
|
||||||
|
def return_config_options(self):
|
||||||
|
config_option = [{'label': 'Script folder',
|
||||||
|
'value': plexpy.CONFIG.SCRIPTS_FOLDER,
|
||||||
|
'name': 'scripts_folder',
|
||||||
|
'description': 'Add your script folder.',
|
||||||
|
'input_type': 'text',
|
||||||
|
},
|
||||||
|
{'label': 'Playback start',
|
||||||
|
'value': plexpy.CONFIG.SCRIPTS_ON_PLAY_SCRIPT,
|
||||||
|
'name': 'scripts_on_play_script',
|
||||||
|
'description': 'Pick the script for on play.',
|
||||||
|
'input_type': 'select',
|
||||||
|
'select_options': self.list_scripts()
|
||||||
|
},
|
||||||
|
{'label': 'Playback stop',
|
||||||
|
'value': plexpy.CONFIG.SCRIPTS_ON_STOP_SCRIPT,
|
||||||
|
'name': 'scripts_on_stop_script',
|
||||||
|
'description': 'Pick the script for on stop.',
|
||||||
|
'input_type': 'select',
|
||||||
|
'select_options': self.list_scripts()
|
||||||
|
},
|
||||||
|
{'label': 'Playback pause',
|
||||||
|
'value': plexpy.CONFIG.SCRIPTS_ON_PAUSE_SCRIPT,
|
||||||
|
'name': 'scripts_on_pause_script',
|
||||||
|
'description': 'Pick the script for on pause.',
|
||||||
|
'input_type': 'select',
|
||||||
|
'select_options': self.list_scripts()
|
||||||
|
},
|
||||||
|
{'label': 'Playback resume',
|
||||||
|
'value': plexpy.CONFIG.SCRIPTS_ON_RESUME_SCRIPT,
|
||||||
|
'name': 'scripts_on_resume_script',
|
||||||
|
'description': 'Pick the script for on resume.',
|
||||||
|
'input_type': 'select',
|
||||||
|
'select_options': self.list_scripts()
|
||||||
|
},
|
||||||
|
{'label': 'On watched',
|
||||||
|
'value': plexpy.CONFIG.SCRIPTS_ON_WATCHED_SCRIPT,
|
||||||
|
'name': 'scripts_on_watched_script',
|
||||||
|
'description': 'Pick the script for on watched.',
|
||||||
|
'input_type': 'select',
|
||||||
|
'select_options': self.list_scripts()
|
||||||
|
},
|
||||||
|
{'label': 'On buffer warning',
|
||||||
|
'value': plexpy.CONFIG.SCRIPTS_ON_BUFFER_SCRIPT,
|
||||||
|
'name': 'scripts_on_buffer_script',
|
||||||
|
'description': 'Pick the script for on buffer.',
|
||||||
|
'input_type': 'select',
|
||||||
|
'select_options': self.list_scripts()
|
||||||
|
},
|
||||||
|
{'label': 'On recently added',
|
||||||
|
'value': plexpy.CONFIG.SCRIPTS_ON_CREATED_SCRIPT,
|
||||||
|
'name': 'scripts_on_created_script',
|
||||||
|
'description': 'Pick the script for recently added.',
|
||||||
|
'input_type': 'select',
|
||||||
|
'select_options': self.list_scripts()
|
||||||
|
},
|
||||||
|
{'label': 'On external connection down',
|
||||||
|
'value': plexpy.CONFIG.SCRIPTS_ON_EXTDOWN_SCRIPT,
|
||||||
|
'name': 'scripts_on_extdown_script',
|
||||||
|
'description': 'Pick the script for external connection down.',
|
||||||
|
'input_type': 'select',
|
||||||
|
'select_options': self.list_scripts()
|
||||||
|
},
|
||||||
|
{'label': 'On external connection down',
|
||||||
|
'value': plexpy.CONFIG.SCRIPTS_ON_EXTUP_SCRIPT,
|
||||||
|
'name': 'scripts_on_extup_script',
|
||||||
|
'description': 'Pick the script for external connection up.',
|
||||||
|
'input_type': 'select',
|
||||||
|
'select_options': self.list_scripts()
|
||||||
|
},
|
||||||
|
{'label': 'On plex down',
|
||||||
|
'value': plexpy.CONFIG.SCRIPTS_ON_INTDOWN_SCRIPT,
|
||||||
|
'name': 'scripts_on_intdown_script',
|
||||||
|
'description': 'Pick the script for pms down',
|
||||||
|
'input_type': 'select',
|
||||||
|
'select_options': self.list_scripts()
|
||||||
|
},
|
||||||
|
{'label': 'On plex up',
|
||||||
|
'value': plexpy.CONFIG.SCRIPTS_ON_INTUP_SCRIPT,
|
||||||
|
'name': 'scripts_on_intup_script',
|
||||||
|
'description': 'Pick the script for pms down',
|
||||||
|
'input_type': 'select',
|
||||||
|
'select_options': self.list_scripts()
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
return config_option
|
|
@ -476,6 +476,7 @@ class WebInterface(object):
|
||||||
"notify_on_extup_body_text": plexpy.CONFIG.NOTIFY_ON_EXTUP_BODY_TEXT,
|
"notify_on_extup_body_text": plexpy.CONFIG.NOTIFY_ON_EXTUP_BODY_TEXT,
|
||||||
"notify_on_intup_subject_text": plexpy.CONFIG.NOTIFY_ON_INTUP_SUBJECT_TEXT,
|
"notify_on_intup_subject_text": plexpy.CONFIG.NOTIFY_ON_INTUP_SUBJECT_TEXT,
|
||||||
"notify_on_intup_body_text": plexpy.CONFIG.NOTIFY_ON_INTUP_BODY_TEXT,
|
"notify_on_intup_body_text": plexpy.CONFIG.NOTIFY_ON_INTUP_BODY_TEXT,
|
||||||
|
"notify_scripts_args_text": plexpy.CONFIG.NOTIFY_SCRIPTS_ARGS_TEXT,
|
||||||
"home_stats_length": plexpy.CONFIG.HOME_STATS_LENGTH,
|
"home_stats_length": plexpy.CONFIG.HOME_STATS_LENGTH,
|
||||||
"home_stats_type": checked(plexpy.CONFIG.HOME_STATS_TYPE),
|
"home_stats_type": checked(plexpy.CONFIG.HOME_STATS_TYPE),
|
||||||
"home_stats_count": plexpy.CONFIG.HOME_STATS_COUNT,
|
"home_stats_count": plexpy.CONFIG.HOME_STATS_COUNT,
|
||||||
|
@ -1420,6 +1421,12 @@ class WebInterface(object):
|
||||||
return serve_template(templatename="notification_triggers_modal.html", title="Notification Triggers",
|
return serve_template(templatename="notification_triggers_modal.html", title="Notification Triggers",
|
||||||
data=this_agent)
|
data=this_agent)
|
||||||
|
|
||||||
|
@cherrypy.expose
|
||||||
|
def testScripts(self, *args, **kwargs):
|
||||||
|
''' Used for manual testing for now cba with adding buttion '''
|
||||||
|
script = notifiers.Scripts()
|
||||||
|
return script.test(*args)
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def delete_history_rows(self, row_id, **kwargs):
|
def delete_history_rows(self, row_id, **kwargs):
|
||||||
data_factory = datafactory.DataFactory()
|
data_factory = datafactory.DataFactory()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue