mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 23:42:37 -07:00
Add notification for user streaming from a new device
This commit is contained in:
parent
f4273cafb6
commit
3ccc82f343
9 changed files with 207 additions and 26 deletions
|
@ -64,6 +64,13 @@
|
|||
</label>
|
||||
<p class="help-block">Trigger notification when a user has concurrent streams.</p>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" data-size="small" data-id="${data['id']}" data-config-name="${data['config_prefix']}_on_newdevice" ${helpers.checked(data['on_newdevice'])} class="toggle-switches">
|
||||
Notify on user new device
|
||||
</label>
|
||||
<p class="help-block">Trigger notification when a user streams from a new device.</p>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" data-size="small" data-id="${data['id']}" data-config-name="${data['config_prefix']}_on_created" ${helpers.checked(data['on_created'])} class="toggle-switches">
|
||||
|
|
|
@ -1059,6 +1059,23 @@
|
|||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<div class="link"><i class="fa fa-desktop fa-fw"></i> User New Device<i class="fa fa-chevron-down"></i></div>
|
||||
<ul class="submenu">
|
||||
<li>
|
||||
<div class="form-group">
|
||||
<label for="notify_on_newdevice_subject_text">Subject Line</label>
|
||||
<input class="form-control" type="text" id="notify_on_newdevice_subject_text" name="notify_on_newdevice_subject_text" value="${config['notify_on_newdevice_subject_text']}" data-parsley-trigger="change" required>
|
||||
<p class="help-block">Set a custom subject line.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="notify_on_buffer_body_text">Message Body</label>
|
||||
<textarea class="form-control" id="notify_on_newdevice_body_text" name="notify_on_newdevice_body_text" data-parsley-trigger="change" data-autoresize required>${config['notify_on_newdevice_body_text']}</textarea>
|
||||
<p class="help-block">Set a custom body.</p>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<ul id="accordion-timeline" class="accordion list-unstyled">
|
||||
<li>
|
||||
|
|
|
@ -18,6 +18,7 @@ import time
|
|||
|
||||
import plexpy
|
||||
import activity_processor
|
||||
import datafactory
|
||||
import helpers
|
||||
import logger
|
||||
import notification_handler
|
||||
|
@ -84,7 +85,17 @@ class ActivityHandler(object):
|
|||
if len(user_sessions) >= plexpy.CONFIG.NOTIFY_CONCURRENT_THRESHOLD:
|
||||
# Push any notifications - Push it on it's own thread so we don't hold up our db actions
|
||||
threading.Thread(target=notification_handler.notify,
|
||||
kwargs=dict(stream_data=session, notify_action='concurrent')).start()
|
||||
kwargs=dict(stream_data=session, notify_action='concurrent')).start()
|
||||
|
||||
# Check if any notification agents have notifications enabled
|
||||
if any(d['on_newdevice'] for d in notifiers.available_notification_agents()):
|
||||
# Check if any concurrent streams by the user
|
||||
data_factory = datafactory.DataFactory()
|
||||
user_devices = data_factory.get_user_devices(user_id=session['user_id'])
|
||||
if session['machine_id'] not in user_devices:
|
||||
# Push any notifications - Push it on it's own thread so we don't hold up our db actions
|
||||
threading.Thread(target=notification_handler.notify,
|
||||
kwargs=dict(stream_data=session, notify_action='newdevice')).start()
|
||||
|
||||
def on_stop(self, force_stop=False):
|
||||
if self.is_valid_session():
|
||||
|
|
|
@ -19,6 +19,7 @@ import re
|
|||
|
||||
import plexpy
|
||||
import database
|
||||
import datafactory
|
||||
import libraries
|
||||
import log_reader
|
||||
import logger
|
||||
|
@ -116,6 +117,16 @@ class ActivityProcessor(object):
|
|||
threading.Thread(target=notification_handler.notify,
|
||||
kwargs=dict(stream_data=values, notify_action='concurrent')).start()
|
||||
|
||||
# Check if any notification agents have notifications enabled
|
||||
if notify and any(d['on_newdevice'] for d in notifiers.available_notification_agents()):
|
||||
# Check if any concurrent streams by the user
|
||||
data_factory = datafactory.DataFactory()
|
||||
user_devices = data_factory.get_user_devices(user_id=session['user_id'])
|
||||
if session['machine_id'] not in user_devices:
|
||||
# Push any notifications - Push it on it's own thread so we don't hold up our db actions
|
||||
threading.Thread(target=notification_handler.notify,
|
||||
kwargs=dict(stream_data=values, notify_action='newdevice')).start()
|
||||
|
||||
return True
|
||||
|
||||
def write_session_history(self, session=None, import_metadata=None, is_import=False, import_ignore_interval=0):
|
||||
|
|
|
@ -81,6 +81,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'BOXCAR_ON_INTUP': (int, 'Boxcar', 0),
|
||||
'BOXCAR_ON_PMSUPDATE': (int, 'Boxcar', 0),
|
||||
'BOXCAR_ON_CONCURRENT': (int, 'Boxcar', 0),
|
||||
'BOXCAR_ON_NEWDEVICE': (int, 'Boxcar', 0),
|
||||
'BROWSER_ENABLED': (int, 'Boxcar', 0),
|
||||
'BROWSER_AUTO_HIDE_DELAY': (int, 'Boxcar', 5),
|
||||
'BROWSER_ON_PLAY': (int, 'BROWSER', 0),
|
||||
|
@ -96,6 +97,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'BROWSER_ON_INTUP': (int, 'BROWSER', 0),
|
||||
'BROWSER_ON_PMSUPDATE': (int, 'BROWSER', 0),
|
||||
'BROWSER_ON_CONCURRENT': (int, 'BROWSER', 0),
|
||||
'BROWSER_ON_NEWDEVICE': (int, 'BROWSER', 0),
|
||||
'BUFFER_THRESHOLD': (int, 'Monitoring', 3),
|
||||
'BUFFER_WAIT': (int, 'Monitoring', 900),
|
||||
'BACKUP_DIR': (str, 'General', ''),
|
||||
|
@ -133,6 +135,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'EMAIL_ON_INTUP': (int, 'Email', 0),
|
||||
'EMAIL_ON_PMSUPDATE': (int, 'Email', 0),
|
||||
'EMAIL_ON_CONCURRENT': (int, 'Email', 0),
|
||||
'EMAIL_ON_NEWDEVICE': (int, 'Email', 0),
|
||||
'ENABLE_HTTPS': (int, 'General', 0),
|
||||
'FACEBOOK_ENABLED': (int, 'Facebook', 0),
|
||||
'FACEBOOK_REDIRECT_URI': (str, 'Facebook', ''),
|
||||
|
@ -156,6 +159,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'FACEBOOK_ON_INTUP': (int, 'Facebook', 0),
|
||||
'FACEBOOK_ON_PMSUPDATE': (int, 'Facebook', 0),
|
||||
'FACEBOOK_ON_CONCURRENT': (int, 'Facebook', 0),
|
||||
'FACEBOOK_ON_NEWDEVICE': (int, 'Facebook', 0),
|
||||
'FIRST_RUN_COMPLETE': (int, 'General', 0),
|
||||
'FREEZE_DB': (int, 'General', 0),
|
||||
'GEOIP_DB': (str, 'General', ''),
|
||||
|
@ -185,6 +189,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'GROWL_ON_INTUP': (int, 'Growl', 0),
|
||||
'GROWL_ON_PMSUPDATE': (int, 'Growl', 0),
|
||||
'GROWL_ON_CONCURRENT': (int, 'Growl', 0),
|
||||
'GROWL_ON_NEWDEVICE': (int, 'Growl', 0),
|
||||
'HOME_SECTIONS': (list, 'General', ['current_activity','watch_stats','library_stats','recently_added']),
|
||||
'HOME_LIBRARY_CARDS': (list, 'General', ['first_run']),
|
||||
'HOME_STATS_LENGTH': (int, 'General', 30),
|
||||
|
@ -225,6 +230,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'IFTTT_ON_INTUP': (int, 'IFTTT', 0),
|
||||
'IFTTT_ON_PMSUPDATE': (int, 'IFTTT', 0),
|
||||
'IFTTT_ON_CONCURRENT': (int, 'IFTTT', 0),
|
||||
'IFTTT_ON_NEWDEVICE': (int, 'IFTTT', 0),
|
||||
'IMGUR_CLIENT_ID': (str, 'Monitoring', ''),
|
||||
'JOIN_APIKEY': (str, 'Join', ''),
|
||||
'JOIN_DEVICEID': (str, 'Join', ''),
|
||||
|
@ -243,6 +249,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'JOIN_ON_INTUP': (int, 'Join', 0),
|
||||
'JOIN_ON_PMSUPDATE': (int, 'Join', 0),
|
||||
'JOIN_ON_CONCURRENT': (int, 'Join', 0),
|
||||
'JOIN_ON_NEWDEVICE': (int, 'Join', 0),
|
||||
'JOURNAL_MODE': (str, 'Advanced', 'wal'),
|
||||
'LAUNCH_BROWSER': (int, 'General', 1),
|
||||
'LOG_BLACKLIST': (int, 'General', 1),
|
||||
|
@ -278,6 +285,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'NMA_ON_INTUP': (int, 'NMA', 0),
|
||||
'NMA_ON_PMSUPDATE': (int, 'NMA', 0),
|
||||
'NMA_ON_CONCURRENT': (int, 'NMA', 0),
|
||||
'NMA_ON_NEWDEVICE': (int, 'NMA', 0),
|
||||
'NOTIFY_CONSECUTIVE': (int, 'Monitoring', 1),
|
||||
'NOTIFY_UPLOAD_POSTERS': (int, 'Monitoring', 0),
|
||||
'NOTIFY_RECENTLY_ADDED': (int, 'Monitoring', 0),
|
||||
|
@ -312,6 +320,8 @@ _CONFIG_DEFINITIONS = {
|
|||
'NOTIFY_ON_PMSUPDATE_BODY_TEXT': (unicode, 'Monitoring', 'An update is available for the Plex Media Server (version {update_version}).'),
|
||||
'NOTIFY_ON_CONCURRENT_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
|
||||
'NOTIFY_ON_CONCURRENT_BODY_TEXT': (unicode, 'Monitoring', '{user} has {user_streams} concurrent streams.'),
|
||||
'NOTIFY_ON_NEWDEVICE_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
|
||||
'NOTIFY_ON_NEWDEVICE_BODY_TEXT': (unicode, 'Monitoring', '{user} is streaming from a new device: {player}.'),
|
||||
'NOTIFY_SCRIPTS_ARGS_TEXT': (unicode, 'Monitoring', ''),
|
||||
'OSX_NOTIFY_APP': (str, 'OSX_Notify', '/Applications/PlexPy'),
|
||||
'OSX_NOTIFY_ENABLED': (int, 'OSX_Notify', 0),
|
||||
|
@ -328,6 +338,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'OSX_NOTIFY_ON_INTUP': (int, 'OSX_Notify', 0),
|
||||
'OSX_NOTIFY_ON_PMSUPDATE': (int, 'OSX_Notify', 0),
|
||||
'OSX_NOTIFY_ON_CONCURRENT': (int, 'OSX_Notify', 0),
|
||||
'OSX_NOTIFY_ON_NEWDEVICE': (int, 'OSX_Notify', 0),
|
||||
'PLEX_CLIENT_HOST': (str, 'Plex', ''),
|
||||
'PLEX_ENABLED': (int, 'Plex', 0),
|
||||
'PLEX_PASSWORD': (str, 'Plex', ''),
|
||||
|
@ -345,6 +356,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'PLEX_ON_INTUP': (int, 'Plex', 0),
|
||||
'PLEX_ON_PMSUPDATE': (int, 'Plex', 0),
|
||||
'PLEX_ON_CONCURRENT': (int, 'Plex', 0),
|
||||
'PLEX_ON_NEWDEVICE': (int, 'Plex', 0),
|
||||
'PROWL_ENABLED': (int, 'Prowl', 0),
|
||||
'PROWL_KEYS': (str, 'Prowl', ''),
|
||||
'PROWL_PRIORITY': (int, 'Prowl', 0),
|
||||
|
@ -361,6 +373,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'PROWL_ON_INTUP': (int, 'Prowl', 0),
|
||||
'PROWL_ON_PMSUPDATE': (int, 'Prowl', 0),
|
||||
'PROWL_ON_CONCURRENT': (int, 'Prowl', 0),
|
||||
'PROWL_ON_NEWDEVICE': (int, 'Prowl', 0),
|
||||
'PUSHALOT_APIKEY': (str, 'Pushalot', ''),
|
||||
'PUSHALOT_ENABLED': (int, 'Pushalot', 0),
|
||||
'PUSHALOT_ON_PLAY': (int, 'Pushalot', 0),
|
||||
|
@ -376,6 +389,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'PUSHALOT_ON_INTUP': (int, 'Pushalot', 0),
|
||||
'PUSHALOT_ON_PMSUPDATE': (int, 'Pushalot', 0),
|
||||
'PUSHALOT_ON_CONCURRENT': (int, 'Pushalot', 0),
|
||||
'PUSHALOT_ON_NEWDEVICE': (int, 'Pushalot', 0),
|
||||
'PUSHBULLET_APIKEY': (str, 'PushBullet', ''),
|
||||
'PUSHBULLET_DEVICEID': (str, 'PushBullet', ''),
|
||||
'PUSHBULLET_CHANNEL_TAG': (str, 'PushBullet', ''),
|
||||
|
@ -393,6 +407,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'PUSHBULLET_ON_INTUP': (int, 'PushBullet', 0),
|
||||
'PUSHBULLET_ON_PMSUPDATE': (int, 'PushBullet', 0),
|
||||
'PUSHBULLET_ON_CONCURRENT': (int, 'PushBullet', 0),
|
||||
'PUSHBULLET_ON_NEWDEVICE': (int, 'PushBullet', 0),
|
||||
'PUSHOVER_APITOKEN': (str, 'Pushover', ''),
|
||||
'PUSHOVER_ENABLED': (int, 'Pushover', 0),
|
||||
'PUSHOVER_HTML_SUPPORT': (int, 'Pushover', 1),
|
||||
|
@ -412,6 +427,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'PUSHOVER_ON_INTUP': (int, 'Pushover', 0),
|
||||
'PUSHOVER_ON_PMSUPDATE': (int, 'Pushover', 0),
|
||||
'PUSHOVER_ON_CONCURRENT': (int, 'Pushover', 0),
|
||||
'PUSHOVER_ON_NEWDEVICE': (int, 'Pushover', 0),
|
||||
'REFRESH_LIBRARIES_INTERVAL': (int, 'Monitoring', 12),
|
||||
'REFRESH_LIBRARIES_ON_STARTUP': (int, 'Monitoring', 1),
|
||||
'REFRESH_USERS_INTERVAL': (int, 'Monitoring', 12),
|
||||
|
@ -438,6 +454,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'SLACK_ON_INTUP': (int, 'Slack', 0),
|
||||
'SLACK_ON_PMSUPDATE': (int, 'Slack', 0),
|
||||
'SLACK_ON_CONCURRENT': (int, 'Slack', 0),
|
||||
'SLACK_ON_NEWDEVICE': (int, 'Slack', 0),
|
||||
'SCRIPTS_ENABLED': (int, 'Scripts', 0),
|
||||
'SCRIPTS_FOLDER': (unicode, 'Scripts', ''),
|
||||
'SCRIPTS_ON_PLAY': (int, 'Scripts', 0),
|
||||
|
@ -453,6 +470,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'SCRIPTS_ON_INTUP': (int, 'Scripts', 0),
|
||||
'SCRIPTS_ON_PMSUPDATE': (int, 'Scripts', 0),
|
||||
'SCRIPTS_ON_CONCURRENT': (int, 'Scripts', 0),
|
||||
'SCRIPTS_ON_NEWDEVICE': (int, 'Scripts', 0),
|
||||
'SCRIPTS_ON_PLAY_SCRIPT': (unicode, 'Scripts', ''),
|
||||
'SCRIPTS_ON_STOP_SCRIPT': (unicode, 'Scripts', ''),
|
||||
'SCRIPTS_ON_PAUSE_SCRIPT': (unicode, 'Scripts', ''),
|
||||
|
@ -466,6 +484,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'SCRIPTS_ON_INTUP_SCRIPT': (unicode, 'Scripts', ''),
|
||||
'SCRIPTS_ON_PMSUPDATE_SCRIPT': (unicode, 'Scripts', ''),
|
||||
'SCRIPTS_ON_CONCURRENT_SCRIPT': (unicode, 'Scripts', ''),
|
||||
'SCRIPTS_ON_NEWDEVICE_SCRIPT': (unicode, 'Scripts', ''),
|
||||
'TELEGRAM_BOT_TOKEN': (str, 'Telegram', ''),
|
||||
'TELEGRAM_ENABLED': (int, 'Telegram', 0),
|
||||
'TELEGRAM_CHAT_ID': (str, 'Telegram', ''),
|
||||
|
@ -485,6 +504,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'TELEGRAM_ON_INTUP': (int, 'Telegram', 0),
|
||||
'TELEGRAM_ON_PMSUPDATE': (int, 'Telegram', 0),
|
||||
'TELEGRAM_ON_CONCURRENT': (int, 'Telegram', 0),
|
||||
'TELEGRAM_ON_NEWDEVICE': (int, 'Telegram', 0),
|
||||
'TV_LOGGING_ENABLE': (int, 'Monitoring', 1),
|
||||
'TV_NOTIFY_ENABLE': (int, 'Monitoring', 0),
|
||||
'TV_NOTIFY_ON_START': (int, 'Monitoring', 1),
|
||||
|
@ -510,6 +530,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'TWITTER_ON_INTUP': (int, 'Twitter', 0),
|
||||
'TWITTER_ON_PMSUPDATE': (int, 'Twitter', 0),
|
||||
'TWITTER_ON_CONCURRENT': (int, 'Twitter', 0),
|
||||
'TWITTER_ON_NEWDEVICE': (int, 'Twitter', 0),
|
||||
'UPDATE_DB_INTERVAL': (int, 'General', 24),
|
||||
'UPDATE_SECTION_IDS': (int, 'General', 1),
|
||||
'UPDATE_LABELS': (int, 'General', 1),
|
||||
|
@ -531,7 +552,8 @@ _CONFIG_DEFINITIONS = {
|
|||
'XBMC_ON_EXTUP': (int, 'XBMC', 0),
|
||||
'XBMC_ON_INTUP': (int, 'XBMC', 0),
|
||||
'XBMC_ON_PMSUPDATE': (int, 'XBMC', 0),
|
||||
'XBMC_ON_CONCURRENT': (int, 'XBMC', 0)
|
||||
'XBMC_ON_CONCURRENT': (int, 'XBMC', 0),
|
||||
'XBMC_ON_NEWDEVICE': (int, 'XBMC', 0)
|
||||
}
|
||||
|
||||
_BLACKLIST_KEYS = ['_APITOKEN', '_TOKEN', '_KEY', '_SECRET', '_PASSWORD', '_APIKEY', '_ID']
|
||||
|
|
|
@ -1306,4 +1306,19 @@ class DataFactory(object):
|
|||
return True
|
||||
except Exception as e:
|
||||
logger.warn(u"PlexPy DataFactory :: Unable to execute database query for delete_notification_log: %s." % e)
|
||||
return False
|
||||
return False
|
||||
|
||||
def get_user_devices(self, user_id=''):
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
if user_id:
|
||||
try:
|
||||
query = 'SELECT machine_id FROM session_history WHERE user_id = ? GROUP BY machine_id'
|
||||
result = monitor_db.select(query=query, args=[user_id])
|
||||
except Exception as e:
|
||||
logger.warn(u"PlexPy DataFactory :: Unable to execute database query for get_user_devices: %s." % e)
|
||||
return []
|
||||
else:
|
||||
return []
|
||||
|
||||
return [d['machine_id'] for d in result]
|
|
@ -202,6 +202,26 @@ def notify(stream_data=None, notify_action=None):
|
|||
notify_strings=notify_strings,
|
||||
metadata=metadata)
|
||||
|
||||
elif agent['on_newdevice'] and notify_action == 'newdevice':
|
||||
# Build and send notification
|
||||
notify_strings, metadata = build_notify_text(session=stream_data,
|
||||
notify_action=notify_action,
|
||||
agent_id=agent['id'])
|
||||
|
||||
notifiers.send_notification(agent_id=agent['id'],
|
||||
subject=notify_strings[0],
|
||||
body=notify_strings[1],
|
||||
script_args=notify_strings[2],
|
||||
notify_action=notify_action,
|
||||
metadata=metadata)
|
||||
|
||||
# Set the notification state in the db
|
||||
set_notify_state(session=stream_data,
|
||||
notify_action=notify_action,
|
||||
agent_info=agent,
|
||||
notify_strings=notify_strings,
|
||||
metadata=metadata)
|
||||
|
||||
elif (stream_data['media_type'] == 'track' and plexpy.CONFIG.MUSIC_NOTIFY_ENABLE):
|
||||
|
||||
for agent in notifiers.available_notification_agents():
|
||||
|
@ -325,6 +345,26 @@ def notify(stream_data=None, notify_action=None):
|
|||
notify_strings=notify_strings,
|
||||
metadata=metadata)
|
||||
|
||||
elif agent['on_newdevice'] and notify_action == 'newdevice':
|
||||
# Build and send notification
|
||||
notify_strings, metadata = build_notify_text(session=stream_data,
|
||||
notify_action=notify_action,
|
||||
agent_id=agent['id'])
|
||||
|
||||
notifiers.send_notification(agent_id=agent['id'],
|
||||
subject=notify_strings[0],
|
||||
body=notify_strings[1],
|
||||
script_args=notify_strings[2],
|
||||
notify_action=notify_action,
|
||||
metadata=metadata)
|
||||
|
||||
# Set the notification state in the db
|
||||
set_notify_state(session=stream_data,
|
||||
notify_action=notify_action,
|
||||
agent_info=agent,
|
||||
notify_strings=notify_strings,
|
||||
metadata=metadata)
|
||||
|
||||
elif stream_data['media_type'] == 'clip':
|
||||
pass
|
||||
else:
|
||||
|
@ -570,6 +610,8 @@ def build_notify_text(session=None, timeline=None, notify_action=None, agent_id=
|
|||
on_created_body = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_CREATED_BODY_TEXT), agent_id)
|
||||
on_concurrent_subject = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_CONCURRENT_SUBJECT_TEXT), agent_id)
|
||||
on_concurrent_body = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_CONCURRENT_BODY_TEXT), agent_id)
|
||||
on_newdevice_subject = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_NEWDEVICE_SUBJECT_TEXT), agent_id)
|
||||
on_newdevice_body = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_NEWDEVICE_BODY_TEXT), agent_id)
|
||||
script_args_text = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_SCRIPTS_ARGS_TEXT), agent_id)
|
||||
else:
|
||||
on_start_subject = strip_tag(plexpy.CONFIG.NOTIFY_ON_START_SUBJECT_TEXT, agent_id)
|
||||
|
@ -588,6 +630,8 @@ def build_notify_text(session=None, timeline=None, notify_action=None, agent_id=
|
|||
on_created_body = strip_tag(plexpy.CONFIG.NOTIFY_ON_CREATED_BODY_TEXT, agent_id)
|
||||
on_concurrent_subject = strip_tag(plexpy.CONFIG.NOTIFY_ON_CONCURRENT_SUBJECT_TEXT, agent_id)
|
||||
on_concurrent_body = strip_tag(plexpy.CONFIG.NOTIFY_ON_CONCURRENT_BODY_TEXT, agent_id)
|
||||
on_newdevice_subject = strip_tag(plexpy.CONFIG.NOTIFY_ON_NEWDEVICE_SUBJECT_TEXT, agent_id)
|
||||
on_newdevice_body = strip_tag(plexpy.CONFIG.NOTIFY_ON_NEWDEVICE_BODY_TEXT, agent_id)
|
||||
script_args_text = strip_tag(plexpy.CONFIG.NOTIFY_SCRIPTS_ARGS_TEXT, agent_id)
|
||||
|
||||
# Create a title
|
||||
|
@ -1011,6 +1055,29 @@ def build_notify_text(session=None, timeline=None, notify_action=None, agent_id=
|
|||
except:
|
||||
logger.error(u"PlexPy NotificationHandler :: Unable to parse custom notification body. Using fallback.")
|
||||
|
||||
return [subject_text, body_text, script_args], metadata
|
||||
else:
|
||||
return [subject_text, body_text, script_args], metadata
|
||||
elif notify_action == 'newdevice':
|
||||
# Default body text
|
||||
body_text = '%s is streaming from a new device: %s.' % (session['friendly_name'],
|
||||
session['player'])
|
||||
|
||||
if on_newdevice_subject and on_newdevice_body:
|
||||
try:
|
||||
subject_text = unicode(on_newdevice_subject).format(**available_params)
|
||||
except LookupError as e:
|
||||
logger.error(u"PlexPy NotificationHandler :: Unable to parse field %s in notification subject. Using fallback." % e)
|
||||
except:
|
||||
logger.error(u"PlexPy NotificationHandler :: Unable to parse custom notification subject. Using fallback.")
|
||||
|
||||
try:
|
||||
body_text = unicode(on_newdevice_body).format(**available_params)
|
||||
except LookupError as e:
|
||||
logger.error(u"PlexPy NotificationHandler :: Unable to parse field %s in notification body. Using fallback." % e)
|
||||
except:
|
||||
logger.error(u"PlexPy NotificationHandler :: Unable to parse custom notification body. Using fallback.")
|
||||
|
||||
return [subject_text, body_text, script_args], metadata
|
||||
else:
|
||||
return [subject_text, body_text, script_args], metadata
|
||||
|
@ -1225,10 +1292,10 @@ def strip_tag(data, agent_id=None):
|
|||
elif agent_id == 13:
|
||||
# Allow tags b, i, code, pre, a[href] for Telegram
|
||||
whitelist = {'b': [],
|
||||
'i': [],
|
||||
'code': [],
|
||||
'pre': [],
|
||||
'a': ['href']}
|
||||
'i': [],
|
||||
'code': [],
|
||||
'pre': [],
|
||||
'a': ['href']}
|
||||
return bleach.clean(data, tags=whitelist.keys(), attributes=whitelist, strip=True)
|
||||
|
||||
else:
|
||||
|
|
|
@ -83,7 +83,8 @@ def available_notification_agents():
|
|||
'on_extup': plexpy.CONFIG.GROWL_ON_EXTUP,
|
||||
'on_intup': plexpy.CONFIG.GROWL_ON_INTUP,
|
||||
'on_pmsupdate': plexpy.CONFIG.GROWL_ON_PMSUPDATE,
|
||||
'on_concurrent': plexpy.CONFIG.GROWL_ON_CONCURRENT
|
||||
'on_concurrent': plexpy.CONFIG.GROWL_ON_CONCURRENT,
|
||||
'on_newdevice': plexpy.CONFIG.GROWL_ON_NEWDEVICE
|
||||
},
|
||||
{'name': 'Prowl',
|
||||
'id': AGENT_IDS['Prowl'],
|
||||
|
@ -102,7 +103,8 @@ def available_notification_agents():
|
|||
'on_extup': plexpy.CONFIG.PROWL_ON_EXTUP,
|
||||
'on_intup': plexpy.CONFIG.PROWL_ON_INTUP,
|
||||
'on_pmsupdate': plexpy.CONFIG.PROWL_ON_PMSUPDATE,
|
||||
'on_concurrent': plexpy.CONFIG.PROWL_ON_CONCURRENT
|
||||
'on_concurrent': plexpy.CONFIG.PROWL_ON_CONCURRENT,
|
||||
'on_newdevice': plexpy.CONFIG.PROWL_ON_NEWDEVICE
|
||||
},
|
||||
{'name': 'XBMC',
|
||||
'id': AGENT_IDS['XBMC'],
|
||||
|
@ -121,7 +123,8 @@ def available_notification_agents():
|
|||
'on_extup': plexpy.CONFIG.XBMC_ON_EXTUP,
|
||||
'on_intup': plexpy.CONFIG.XBMC_ON_INTUP,
|
||||
'on_pmsupdate': plexpy.CONFIG.XBMC_ON_PMSUPDATE,
|
||||
'on_concurrent': plexpy.CONFIG.XBMC_ON_CONCURRENT
|
||||
'on_concurrent': plexpy.CONFIG.XBMC_ON_CONCURRENT,
|
||||
'on_newdevice': plexpy.CONFIG.XBMC_ON_NEWDEVICE
|
||||
},
|
||||
{'name': 'Plex Home Theater',
|
||||
'id': AGENT_IDS['Plex'],
|
||||
|
@ -140,7 +143,8 @@ def available_notification_agents():
|
|||
'on_extup': plexpy.CONFIG.PLEX_ON_EXTUP,
|
||||
'on_intup': plexpy.CONFIG.PLEX_ON_INTUP,
|
||||
'on_pmsupdate': plexpy.CONFIG.PLEX_ON_PMSUPDATE,
|
||||
'on_concurrent': plexpy.CONFIG.PLEX_ON_CONCURRENT
|
||||
'on_concurrent': plexpy.CONFIG.PLEX_ON_CONCURRENT,
|
||||
'on_newdevice': plexpy.CONFIG.PLEX_ON_NEWDEVICE
|
||||
},
|
||||
{'name': 'NotifyMyAndroid',
|
||||
'id': AGENT_IDS['NMA'],
|
||||
|
@ -159,7 +163,8 @@ def available_notification_agents():
|
|||
'on_extup': plexpy.CONFIG.NMA_ON_EXTUP,
|
||||
'on_intup': plexpy.CONFIG.NMA_ON_INTUP,
|
||||
'on_pmsupdate': plexpy.CONFIG.NMA_ON_PMSUPDATE,
|
||||
'on_concurrent': plexpy.CONFIG.NMA_ON_CONCURRENT
|
||||
'on_concurrent': plexpy.CONFIG.NMA_ON_CONCURRENT,
|
||||
'on_newdevice': plexpy.CONFIG.NMA_ON_NEWDEVICE
|
||||
},
|
||||
{'name': 'Pushalot',
|
||||
'id': AGENT_IDS['Pushalot'],
|
||||
|
@ -178,7 +183,8 @@ def available_notification_agents():
|
|||
'on_extup': plexpy.CONFIG.PUSHALOT_ON_EXTUP,
|
||||
'on_intup': plexpy.CONFIG.PUSHALOT_ON_INTUP,
|
||||
'on_pmsupdate': plexpy.CONFIG.PUSHALOT_ON_PMSUPDATE,
|
||||
'on_concurrent': plexpy.CONFIG.PUSHALOT_ON_CONCURRENT
|
||||
'on_concurrent': plexpy.CONFIG.PUSHALOT_ON_CONCURRENT,
|
||||
'on_newdevice': plexpy.CONFIG.PUSHALOT_ON_NEWDEVICE
|
||||
},
|
||||
{'name': 'Pushbullet',
|
||||
'id': AGENT_IDS['Pushbullet'],
|
||||
|
@ -197,7 +203,8 @@ def available_notification_agents():
|
|||
'on_extup': plexpy.CONFIG.PUSHBULLET_ON_EXTUP,
|
||||
'on_intup': plexpy.CONFIG.PUSHBULLET_ON_INTUP,
|
||||
'on_pmsupdate': plexpy.CONFIG.PUSHBULLET_ON_PMSUPDATE,
|
||||
'on_concurrent': plexpy.CONFIG.PUSHBULLET_ON_CONCURRENT
|
||||
'on_concurrent': plexpy.CONFIG.PUSHBULLET_ON_CONCURRENT,
|
||||
'on_newdevice': plexpy.CONFIG.PUSHBULLET_ON_NEWDEVICE
|
||||
},
|
||||
{'name': 'Pushover',
|
||||
'id': AGENT_IDS['Pushover'],
|
||||
|
@ -216,7 +223,8 @@ def available_notification_agents():
|
|||
'on_extup': plexpy.CONFIG.PUSHOVER_ON_EXTUP,
|
||||
'on_intup': plexpy.CONFIG.PUSHOVER_ON_INTUP,
|
||||
'on_pmsupdate': plexpy.CONFIG.PUSHOVER_ON_PMSUPDATE,
|
||||
'on_concurrent': plexpy.CONFIG.PUSHOVER_ON_CONCURRENT
|
||||
'on_concurrent': plexpy.CONFIG.PUSHOVER_ON_CONCURRENT,
|
||||
'on_newdevice': plexpy.CONFIG.PUSHOVER_ON_NEWDEVICE
|
||||
},
|
||||
{'name': 'Boxcar2',
|
||||
'id': AGENT_IDS['Boxcar2'],
|
||||
|
@ -235,7 +243,8 @@ def available_notification_agents():
|
|||
'on_extup': plexpy.CONFIG.BOXCAR_ON_EXTUP,
|
||||
'on_intup': plexpy.CONFIG.BOXCAR_ON_INTUP,
|
||||
'on_pmsupdate': plexpy.CONFIG.BOXCAR_ON_PMSUPDATE,
|
||||
'on_concurrent': plexpy.CONFIG.BOXCAR_ON_CONCURRENT
|
||||
'on_concurrent': plexpy.CONFIG.BOXCAR_ON_CONCURRENT,
|
||||
'on_newdevice': plexpy.CONFIG.BOXCAR_ON_NEWDEVICE
|
||||
},
|
||||
{'name': 'E-mail',
|
||||
'id': AGENT_IDS['Email'],
|
||||
|
@ -254,7 +263,8 @@ def available_notification_agents():
|
|||
'on_extup': plexpy.CONFIG.EMAIL_ON_EXTUP,
|
||||
'on_intup': plexpy.CONFIG.EMAIL_ON_INTUP,
|
||||
'on_pmsupdate': plexpy.CONFIG.EMAIL_ON_PMSUPDATE,
|
||||
'on_concurrent': plexpy.CONFIG.EMAIL_ON_CONCURRENT
|
||||
'on_concurrent': plexpy.CONFIG.EMAIL_ON_CONCURRENT,
|
||||
'on_newdevice': plexpy.CONFIG.EMAIL_ON_NEWDEVICE
|
||||
},
|
||||
{'name': 'Twitter',
|
||||
'id': AGENT_IDS['Twitter'],
|
||||
|
@ -273,7 +283,8 @@ def available_notification_agents():
|
|||
'on_extup': plexpy.CONFIG.TWITTER_ON_EXTUP,
|
||||
'on_intup': plexpy.CONFIG.TWITTER_ON_INTUP,
|
||||
'on_pmsupdate': plexpy.CONFIG.TWITTER_ON_PMSUPDATE,
|
||||
'on_concurrent': plexpy.CONFIG.TWITTER_ON_CONCURRENT
|
||||
'on_concurrent': plexpy.CONFIG.TWITTER_ON_CONCURRENT,
|
||||
'on_newdevice': plexpy.CONFIG.TWITTER_ON_NEWDEVICE
|
||||
},
|
||||
{'name': 'IFTTT',
|
||||
'id': AGENT_IDS['IFTTT'],
|
||||
|
@ -292,7 +303,8 @@ def available_notification_agents():
|
|||
'on_extup': plexpy.CONFIG.IFTTT_ON_EXTUP,
|
||||
'on_intup': plexpy.CONFIG.IFTTT_ON_INTUP,
|
||||
'on_pmsupdate': plexpy.CONFIG.IFTTT_ON_PMSUPDATE,
|
||||
'on_concurrent': plexpy.CONFIG.IFTTT_ON_CONCURRENT
|
||||
'on_concurrent': plexpy.CONFIG.IFTTT_ON_CONCURRENT,
|
||||
'on_newdevice': plexpy.CONFIG.IFTTT_ON_NEWDEVICE
|
||||
},
|
||||
{'name': 'Telegram',
|
||||
'id': AGENT_IDS['Telegram'],
|
||||
|
@ -311,7 +323,8 @@ def available_notification_agents():
|
|||
'on_extup': plexpy.CONFIG.TELEGRAM_ON_EXTUP,
|
||||
'on_intup': plexpy.CONFIG.TELEGRAM_ON_INTUP,
|
||||
'on_pmsupdate': plexpy.CONFIG.TELEGRAM_ON_PMSUPDATE,
|
||||
'on_concurrent': plexpy.CONFIG.TELEGRAM_ON_CONCURRENT
|
||||
'on_concurrent': plexpy.CONFIG.TELEGRAM_ON_CONCURRENT,
|
||||
'on_newdevice': plexpy.CONFIG.TELEGRAM_ON_NEWDEVICE
|
||||
},
|
||||
{'name': 'Slack',
|
||||
'id': AGENT_IDS['Slack'],
|
||||
|
@ -330,7 +343,8 @@ def available_notification_agents():
|
|||
'on_extup': plexpy.CONFIG.SLACK_ON_EXTUP,
|
||||
'on_intup': plexpy.CONFIG.SLACK_ON_INTUP,
|
||||
'on_pmsupdate': plexpy.CONFIG.SLACK_ON_PMSUPDATE,
|
||||
'on_concurrent': plexpy.CONFIG.SLACK_ON_CONCURRENT
|
||||
'on_concurrent': plexpy.CONFIG.SLACK_ON_CONCURRENT,
|
||||
'on_newdevice': plexpy.CONFIG.SLACK_ON_NEWDEVICE
|
||||
},
|
||||
{'name': 'Scripts',
|
||||
'id': AGENT_IDS['Scripts'],
|
||||
|
@ -349,7 +363,8 @@ def available_notification_agents():
|
|||
'on_intdown': plexpy.CONFIG.SCRIPTS_ON_INTDOWN,
|
||||
'on_intup': plexpy.CONFIG.SCRIPTS_ON_INTUP,
|
||||
'on_pmsupdate': plexpy.CONFIG.SCRIPTS_ON_PMSUPDATE,
|
||||
'on_concurrent': plexpy.CONFIG.SCRIPTS_ON_CONCURRENT
|
||||
'on_concurrent': plexpy.CONFIG.SCRIPTS_ON_CONCURRENT,
|
||||
'on_newdevice': plexpy.CONFIG.SCRIPTS_ON_NEWDEVICE
|
||||
},
|
||||
{'name': 'Facebook',
|
||||
'id': AGENT_IDS['Facebook'],
|
||||
|
@ -368,7 +383,8 @@ def available_notification_agents():
|
|||
'on_extup': plexpy.CONFIG.FACEBOOK_ON_EXTUP,
|
||||
'on_intup': plexpy.CONFIG.FACEBOOK_ON_INTUP,
|
||||
'on_pmsupdate': plexpy.CONFIG.FACEBOOK_ON_PMSUPDATE,
|
||||
'on_concurrent': plexpy.CONFIG.FACEBOOK_ON_CONCURRENT
|
||||
'on_concurrent': plexpy.CONFIG.FACEBOOK_ON_CONCURRENT,
|
||||
'on_newdevice': plexpy.CONFIG.FACEBOOK_ON_NEWDEVICE
|
||||
},
|
||||
{'name': 'Browser',
|
||||
'id': AGENT_IDS['Browser'],
|
||||
|
@ -387,7 +403,8 @@ def available_notification_agents():
|
|||
'on_extup': plexpy.CONFIG.BROWSER_ON_EXTUP,
|
||||
'on_intup': plexpy.CONFIG.BROWSER_ON_INTUP,
|
||||
'on_pmsupdate': plexpy.CONFIG.BROWSER_ON_PMSUPDATE,
|
||||
'on_concurrent': plexpy.CONFIG.BROWSER_ON_CONCURRENT
|
||||
'on_concurrent': plexpy.CONFIG.BROWSER_ON_CONCURRENT,
|
||||
'on_newdevice': plexpy.CONFIG.BROWSER_ON_NEWDEVICE
|
||||
},
|
||||
{'name': 'Join',
|
||||
'id': AGENT_IDS['Join'],
|
||||
|
@ -406,7 +423,8 @@ def available_notification_agents():
|
|||
'on_extup': plexpy.CONFIG.JOIN_ON_EXTUP,
|
||||
'on_intup': plexpy.CONFIG.JOIN_ON_INTUP,
|
||||
'on_pmsupdate': plexpy.CONFIG.JOIN_ON_PMSUPDATE,
|
||||
'on_concurrent': plexpy.CONFIG.JOIN_ON_CONCURRENT
|
||||
'on_concurrent': plexpy.CONFIG.JOIN_ON_CONCURRENT,
|
||||
'on_newdevice': plexpy.CONFIG.JOIN_ON_NEWDEVICE
|
||||
}
|
||||
]
|
||||
|
||||
|
@ -430,7 +448,8 @@ def available_notification_agents():
|
|||
'on_extup': plexpy.CONFIG.OSX_NOTIFY_ON_EXTUP,
|
||||
'on_intup': plexpy.CONFIG.OSX_NOTIFY_ON_INTUP,
|
||||
'on_pmsupdate': plexpy.CONFIG.OSX_NOTIFY_ON_PMSUPDATE,
|
||||
'on_concurrent': plexpy.CONFIG.OSX_NOTIFY_ON_CONCURRENT
|
||||
'on_concurrent': plexpy.CONFIG.OSX_NOTIFY_ON_CONCURRENT,
|
||||
'on_newdevice': plexpy.CONFIG.OSX_NOTIFY_ON_NEWDEVICE
|
||||
})
|
||||
|
||||
return agents
|
||||
|
@ -2112,6 +2131,9 @@ class Scripts(object):
|
|||
elif notify_action == 'concurrent':
|
||||
script = plexpy.CONFIG.SCRIPTS_ON_CONCURRENT_SCRIPT
|
||||
|
||||
elif notify_action == 'newdevice':
|
||||
script = plexpy.CONFIG.SCRIPTS_ON_NEWDEVICE_SCRIPT
|
||||
|
||||
else:
|
||||
# For manual scripts
|
||||
script = kwargs.get('script', '')
|
||||
|
@ -2295,6 +2317,13 @@ class Scripts(object):
|
|||
'description': 'Choose the script for user concurrent streams.',
|
||||
'input_type': 'select',
|
||||
'select_options': self.list_scripts()
|
||||
},
|
||||
{'label': 'User New Device',
|
||||
'value': plexpy.CONFIG.SCRIPTS_ON_NEWDEVICE_SCRIPT,
|
||||
'name': 'scripts_on_newdevice_script',
|
||||
'description': 'Choose the script for user new device.',
|
||||
'input_type': 'select',
|
||||
'select_options': self.list_scripts()
|
||||
}
|
||||
]
|
||||
|
||||
|
|
|
@ -2598,6 +2598,8 @@ class WebInterface(object):
|
|||
"notify_on_pmsupdate_body_text": plexpy.CONFIG.NOTIFY_ON_PMSUPDATE_BODY_TEXT,
|
||||
"notify_on_concurrent_subject_text": plexpy.CONFIG.NOTIFY_ON_CONCURRENT_SUBJECT_TEXT,
|
||||
"notify_on_concurrent_body_text": plexpy.CONFIG.NOTIFY_ON_CONCURRENT_BODY_TEXT,
|
||||
"notify_on_newdevice_subject_text": plexpy.CONFIG.NOTIFY_ON_NEWDEVICE_SUBJECT_TEXT,
|
||||
"notify_on_newdevice_body_text": plexpy.CONFIG.NOTIFY_ON_NEWDEVICE_BODY_TEXT,
|
||||
"notify_scripts_args_text": plexpy.CONFIG.NOTIFY_SCRIPTS_ARGS_TEXT,
|
||||
"home_sections": json.dumps(plexpy.CONFIG.HOME_SECTIONS),
|
||||
"home_stats_length": plexpy.CONFIG.HOME_STATS_LENGTH,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue