Added basic notification controls.

This commit is contained in:
Tim 2015-07-09 00:12:19 +02:00
parent 69c8441c1c
commit e83c9321d4
5 changed files with 180 additions and 10 deletions

View file

@ -40,7 +40,8 @@
<ul class="nav nav-pills" role="tablist"> <ul class="nav nav-pills" role="tablist">
<li role="presentation" class="active"><a href="#tabs-1" aria-controls="tabs-1" role="tab" data-toggle="tab">Web Interface</a></li> <li role="presentation" class="active"><a href="#tabs-1" aria-controls="tabs-1" role="tab" data-toggle="tab">Web Interface</a></li>
<li role="presentation"><a href="#tabs-2" aria-controls="tabs-2" role="tab" data-toggle="tab">Plex & PlexWatch</a></li> <li role="presentation"><a href="#tabs-2" aria-controls="tabs-2" role="tab" data-toggle="tab">Plex & PlexWatch</a></li>
<li role="presentation"><a href="#tabs-5" aria-controls="tabs-5" role="tab" data-toggle="tab">Notifications</a></li> <li role="presentation"><a href="#tabs-3" aria-controls="tabs-3" role="tab" data-toggle="tab">Monitoring</a></li>
<li role="presentation"><a href="#tabs-5" aria-controls="tabs-5" role="tab" data-toggle="tab">Notification Agents</a></li>
</ul> </ul>
<div class="tab-content"> <div class="tab-content">
@ -219,6 +220,68 @@
<input type="button" class="btn btn-medium btn-primary save-button" value="Save" data-success="Changes saved successfully"> <input type="button" class="btn btn-medium btn-primary save-button" value="Save" data-success="Changes saved successfully">
</div> </div>
<div role="tabpanel" class="tab-pane" id="tabs-3">
<div class="wellbg" style="padding: 0px 0px 0px 20px;">
<div class="container-fluid">
<div class="row-fluid">
<div class="span4">
<fieldset>
<div class="wellheader">
<h3>Global Notifications</h3>
</div>
<dl>
<dt>
<div class="checkbox">
<input type="checkbox" name="tv_notify_enable" id="tv_notify_enable" value="1" ${config['tv_notify_enable']}> Enable TV Notifications
</div>
</dt>
<dd>
<div id="tv_notify_options" data-parsley-group="tv_notify">
<div class="checkbox">
<input type="checkbox" name="tv_notify_on_start" id="tv_notify_on_start" data-parsley-multiple="tv_notify" data-parsley-mincheck="1" data-parsley-required value="1" ${config['tv_notify_on_start']}> Notify on playback start
</div>
<br/>
</div>
</dd>
</dl>
<dl>
<dt>
<div class="checkbox">
<input type="checkbox" name="movie_notify_enable" id="movie_notify_enable" value="1" ${config['movie_notify_enable']}> Enable Movie Notifications
</div>
</dt>
<dd>
<div id="movie_notify_options" data-parsley-group="movie_notify">
<div class="checkbox">
<input type="checkbox" name="movie_notify_on_start" id="movie_notify_on_start" data-parsley-multiple="movie_notify" data-parsley-mincheck="1" data-parsley-required value="1" ${config['movie_notify_on_start']}> Notify on playback start
</div>
<br/>
</div>
</dd>
</dl>
<dl>
<dt>
<div class="checkbox">
<input type="checkbox" name="music_notify_enable" id="music_notify_enable" value="1" ${config['music_notify_enable']}> Enable Music Notifications
</div>
</dt>
<dd>
<div id="music_notify_options" data-parsley-group="music_notify">
<div class="checkbox">
<input type="checkbox" name="music_notify_on_start" id="music_notify_on_start" data-parsley-multiple="music_notify" data-parsley-mincheck="1" data-parsley-required value="1" ${config['music_notify_on_start']}> Notify on playback start
</div>
</div>
</dd>
</dl>
</fieldset>
</div>
</div>
</div>
</div>
<br/>
<input type="button" class="btn btn-medium btn-primary save-button" value="Save" data-success="Changes saved successfully">
</div>
<div role="tabpanel" class="tab-pane" id="tabs-5"> <div role="tabpanel" class="tab-pane" id="tabs-5">
<div class="wellbg" style="padding: 0px 0px 0px 20px;"> <div class="wellbg" style="padding: 0px 0px 0px 20px;">
<div class="container-fluid"> <div class="container-fluid">
@ -1024,6 +1087,66 @@
} }
}); });
if ($("#tv_notify_enable").is(":checked"))
{
$("#tv_notify_options").show();
}
else
{
$("#tv_notify_options").hide();
}
$("#tv_notify_enable").click(function(){
if ($("#tv_notify_enable").is(":checked"))
{
$("#tv_notify_options").slideDown();
}
else
{
$("#tv_notify_options").slideUp();
}
});
if ($("#movie_notify_enable").is(":checked"))
{
$("#movie_notify_options").show();
}
else
{
$("#movie_notify_options").hide();
}
$("#movie_notify_enable").click(function(){
if ($("#movie_notify_enable").is(":checked"))
{
$("#movie_notify_options").slideDown();
}
else
{
$("#movie_notify_options").slideUp();
}
});
if ($("#music_notify_enable").is(":checked"))
{
$("#music_notify_options").show();
}
else
{
$("#music_notify_options").hide();
}
$("#music_notify_enable").click(function(){
if ($("#music_notify_enable").is(":checked"))
{
$("#music_notify_options").slideDown();
}
else
{
$("#music_notify_options").slideUp();
}
});
initConfigCheckbox("#api_enabled"); initConfigCheckbox("#api_enabled");
initConfigCheckbox("#enable_https"); initConfigCheckbox("#enable_https");

View file

@ -29,12 +29,12 @@ from plexpy import version
USER_AGENT = 'PlexPy/-' + version.PLEXPY_VERSION + ' (' + platform.system() + ' ' + platform.release() + ')' USER_AGENT = 'PlexPy/-' + version.PLEXPY_VERSION + ' (' + platform.system() + ' ' + platform.release() + ')'
# Notification Types # Notification Types
NOTIFY_SNATCH = 1 NOTIFY_STARTED = 1
NOTIFY_DOWNLOAD = 2 NOTIFY_STOPPED = 2
notifyStrings = {} notify_strings = {}
notifyStrings[NOTIFY_SNATCH] = "Started Download" notify_strings[NOTIFY_STARTED] = "Playback started"
notifyStrings[NOTIFY_DOWNLOAD] = "Download Finished" notify_strings[NOTIFY_STOPPED] = "Playback stopped"
DEFAULT_USER_THUMB = "interfaces/default/images/gravatar-default-80x80.png" DEFAULT_USER_THUMB = "interfaces/default/images/gravatar-default-80x80.png"
DEFAULT_POSTER_THUMB = "interfaces/default/images/poster.png" DEFAULT_POSTER_THUMB = "interfaces/default/images/poster.png"

View file

@ -72,6 +72,10 @@ _CONFIG_DEFINITIONS = {
'JOURNAL_MODE': (str, 'Advanced', 'wal'), 'JOURNAL_MODE': (str, 'Advanced', 'wal'),
'LAUNCH_BROWSER': (int, 'General', 1), 'LAUNCH_BROWSER': (int, 'General', 1),
'LOG_DIR': (str, 'General', ''), 'LOG_DIR': (str, 'General', ''),
'MOVIE_NOTIFY_ENABLE': (int, 'Monitoring', 0),
'MOVIE_NOTIFY_ON_START': (int, 'Monitoring', 1),
'MUSIC_NOTIFY_ENABLE': (int, 'Monitoring', 0),
'MUSIC_NOTIFY_ON_START': (int, 'Monitoring', 1),
'NMA_APIKEY': (str, 'NMA', ''), 'NMA_APIKEY': (str, 'NMA', ''),
'NMA_ENABLED': (int, 'NMA', 0), 'NMA_ENABLED': (int, 'NMA', 0),
'NMA_PRIORITY': (int, 'NMA', 0), 'NMA_PRIORITY': (int, 'NMA', 0),
@ -93,6 +97,8 @@ _CONFIG_DEFINITIONS = {
'PUSHOVER_ENABLED': (int, 'Pushover', 0), 'PUSHOVER_ENABLED': (int, 'Pushover', 0),
'PUSHOVER_KEYS': (str, 'Pushover', ''), 'PUSHOVER_KEYS': (str, 'Pushover', ''),
'PUSHOVER_PRIORITY': (int, 'Pushover', 0), 'PUSHOVER_PRIORITY': (int, 'Pushover', 0),
'TV_NOTIFY_ENABLE': (int, 'Monitoring', 0),
'TV_NOTIFY_ON_START': (int, 'Monitoring', 1),
'TWITTER_ENABLED': (int, 'Twitter', 0), 'TWITTER_ENABLED': (int, 'Twitter', 0),
'TWITTER_PASSWORD': (str, 'Twitter', ''), 'TWITTER_PASSWORD': (str, 'Twitter', ''),
'TWITTER_PREFIX': (str, 'Twitter', 'Headphones'), 'TWITTER_PREFIX': (str, 'Twitter', 'Headphones'),

View file

@ -13,7 +13,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>. # along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
from plexpy import logger, helpers, plexwatch, pmsconnect, notification_handler, config, log_reader from plexpy import logger, helpers, plexwatch, pmsconnect, notification_handler, config, log_reader, common
from xml.dom import minidom from xml.dom import minidom
from httplib import HTTPSConnection from httplib import HTTPSConnection
@ -50,6 +50,7 @@ def check_active_sessions():
parent_title = session['parent_title'] parent_title = session['parent_title']
grandparent_title = session['grandparent_title'] grandparent_title = session['grandparent_title']
machine_id = session['machine_id'] machine_id = session['machine_id']
user = session['user']
write_session = monitor_db.write_session_key(session_key, rating_key, media_type) write_session = monitor_db.write_session_key(session_key, rating_key, media_type)
if write_session == 'insert': if write_session == 'insert':
@ -62,7 +63,10 @@ def check_active_sessions():
item_title = title item_title = title
logger.info('%s (%s) starting playing %s' % (friendly_name, platform, item_title)) logger.info('%s (%s) starting playing %s' % (friendly_name, platform, item_title))
pushmessage = '%s (%s) starting playing %s' % (friendly_name, platform, item_title) pushmessage = '%s (%s) starting playing %s' % (friendly_name, platform, item_title)
notification_handler.push_nofitications(pushmessage, 'PlexPy Playback started', 'Playback Started')
# Push any notifications
monitor_notifications = MonitorNotifications(media_type=media_type, user=user)
monitor_notifications.notify(pushmessage)
# Try and grab IP address from logs # Try and grab IP address from logs
if plexpy.CONFIG.PMS_LOGS_FOLDER: if plexpy.CONFIG.PMS_LOGS_FOLDER:
@ -247,3 +251,32 @@ class MonitorProcessing(object):
logger.debug(u"Unable to find IP address on fallback search. Not logging IP address.") logger.debug(u"Unable to find IP address on fallback search. Not logging IP address.")
return None return None
class MonitorNotifications(object):
def __init__(self, media_type, user=None):
self.media_type = media_type
self.user = user
self.tv_notify_enabled = plexpy.CONFIG.TV_NOTIFY_ENABLE
self.movie_notify_enabled = plexpy.CONFIG.MOVIE_NOTIFY_ENABLE
self.music_notify_enabled = plexpy.CONFIG.MUSIC_NOTIFY_ENABLE
def notify(self, message=None):
if message:
if self.media_type == 'movie':
if self.movie_notify_enabled:
notification_handler.push_nofitications(message, 'PlexPy', common.notify_strings[1])
elif self.media_type == 'episode':
if self.tv_notify_enabled:
notification_handler.push_nofitications(message, 'PlexPy', common.notify_strings[1])
elif self.media_type == 'track':
if self.music_notify_enabled:
notification_handler.push_nofitications(message, 'PlexPy', common.notify_strings[1])
elif self.media_type == 'clip':
pass
else:
logger.debug(u"Notify called with unsupported media type.")
pass
else:
logger.debug(u"Notify called without a message.")

View file

@ -329,7 +329,13 @@ class WebInterface(object):
"time_format": plexpy.CONFIG.TIME_FORMAT, "time_format": plexpy.CONFIG.TIME_FORMAT,
"grouping_global_history": checked(plexpy.CONFIG.GROUPING_GLOBAL_HISTORY), "grouping_global_history": checked(plexpy.CONFIG.GROUPING_GLOBAL_HISTORY),
"grouping_user_history": checked(plexpy.CONFIG.GROUPING_USER_HISTORY), "grouping_user_history": checked(plexpy.CONFIG.GROUPING_USER_HISTORY),
"grouping_charts": checked(plexpy.CONFIG.GROUPING_CHARTS) "grouping_charts": checked(plexpy.CONFIG.GROUPING_CHARTS),
"tv_notify_enable": checked(plexpy.CONFIG.TV_NOTIFY_ENABLE),
"movie_notify_enable": checked(plexpy.CONFIG.MOVIE_NOTIFY_ENABLE),
"music_notify_enable": checked(plexpy.CONFIG.MUSIC_NOTIFY_ENABLE),
"tv_notify_on_start": checked(plexpy.CONFIG.TV_NOTIFY_ON_START),
"movie_notify_on_start": checked(plexpy.CONFIG.MOVIE_NOTIFY_ON_START),
"music_notify_on_start": checked(plexpy.CONFIG.MUSIC_NOTIFY_ON_START)
} }
return serve_template(templatename="config.html", title="Settings", config=config) return serve_template(templatename="config.html", title="Settings", config=config)
@ -345,7 +351,9 @@ class WebInterface(object):
"pushover_enabled", "pushbullet_enabled", "pushover_enabled", "pushbullet_enabled",
"twitter_enabled", "osx_notify_enabled", "twitter_enabled", "osx_notify_enabled",
"boxcar_enabled", "email_enabled", "email_tls", "boxcar_enabled", "email_enabled", "email_tls",
"grouping_global_history", "grouping_user_history", "grouping_charts", "pms_use_bif" "grouping_global_history", "grouping_user_history", "grouping_charts", "pms_use_bif",
"tv_notify_enable", "movie_notify_enable", "music_notify_enable",
"tv_notify_on_start", "movie_notify_on_start", "music_notify_on_start"
] ]
for checked_config in checked_configs: for checked_config in checked_configs:
if checked_config not in kwargs: if checked_config not in kwargs: