mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-08 06:00:51 -07:00
Update notification handler for all notification triggers
This commit is contained in:
parent
1206d13978
commit
7b2a7aff9f
7 changed files with 245 additions and 1034 deletions
|
@ -10,7 +10,7 @@ DOCUMENTATION :: END
|
||||||
</%doc>
|
</%doc>
|
||||||
|
|
||||||
<ul class="stacked-configs list-unstyled">
|
<ul class="stacked-configs list-unstyled">
|
||||||
% for notifier in notifiers_list:
|
% for notifier in sorted(notifiers_list, key=lambda k: (k['agent_label'], k['id'])):
|
||||||
<li>
|
<li>
|
||||||
<span>
|
<span>
|
||||||
<span class="toggle-left trigger-tooltip ${'active' if notifier['active'] else ''}" data-toggle="tooltip" data-placement="top" title="Triggers active"><i class="fa fa-lg fa-bell"></i></span>
|
<span class="toggle-left trigger-tooltip ${'active' if notifier['active'] else ''}" data-toggle="tooltip" data-placement="top" title="Triggers active"><i class="fa fa-lg fa-bell"></i></span>
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
|
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from Queue import Queue
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -35,6 +36,7 @@ import activity_pinger
|
||||||
import config
|
import config
|
||||||
import database
|
import database
|
||||||
import logger
|
import logger
|
||||||
|
import notification_handler
|
||||||
import plextv
|
import plextv
|
||||||
import pmsconnect
|
import pmsconnect
|
||||||
import versioncheck
|
import versioncheck
|
||||||
|
@ -58,6 +60,8 @@ PIDFILE = None
|
||||||
SCHED = BackgroundScheduler()
|
SCHED = BackgroundScheduler()
|
||||||
SCHED_LOCK = threading.Lock()
|
SCHED_LOCK = threading.Lock()
|
||||||
|
|
||||||
|
NOTIFY_QUEUE = Queue()
|
||||||
|
|
||||||
INIT_LOCK = threading.Lock()
|
INIT_LOCK = threading.Lock()
|
||||||
_INITIALIZED = False
|
_INITIALIZED = False
|
||||||
started = False
|
started = False
|
||||||
|
@ -345,7 +349,6 @@ def initialize_scheduler():
|
||||||
# Debug
|
# Debug
|
||||||
#SCHED.print_jobs()
|
#SCHED.print_jobs()
|
||||||
|
|
||||||
|
|
||||||
def schedule_job(function, name, hours=0, minutes=0, seconds=0, args=None):
|
def schedule_job(function, name, hours=0, minutes=0, seconds=0, args=None):
|
||||||
"""
|
"""
|
||||||
Start scheduled job if starting or restarting plexpy.
|
Start scheduled job if starting or restarting plexpy.
|
||||||
|
@ -374,6 +377,13 @@ def start():
|
||||||
|
|
||||||
if _INITIALIZED:
|
if _INITIALIZED:
|
||||||
initialize_scheduler()
|
initialize_scheduler()
|
||||||
|
|
||||||
|
# Start background notification thread
|
||||||
|
if any([CONFIG.MOVIE_NOTIFY_ENABLE, CONFIG.TV_NOTIFY_ENABLE,
|
||||||
|
CONFIG.MUSIC_NOTIFY_ENABLE, CONFIG.NOTIFY_RECENTLY_ADDED]):
|
||||||
|
logger.info(u"Starting background notification handler.")
|
||||||
|
notification_handler.start_thread(num_threads=3)
|
||||||
|
|
||||||
started = True
|
started = True
|
||||||
|
|
||||||
|
|
||||||
|
@ -450,8 +460,8 @@ def dbcheck():
|
||||||
c_db.execute(
|
c_db.execute(
|
||||||
'CREATE TABLE IF NOT EXISTS notify_log (id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp INTEGER, '
|
'CREATE TABLE IF NOT EXISTS notify_log (id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp INTEGER, '
|
||||||
'session_key INTEGER, rating_key INTEGER, parent_rating_key INTEGER, grandparent_rating_key INTEGER, '
|
'session_key INTEGER, rating_key INTEGER, parent_rating_key INTEGER, grandparent_rating_key INTEGER, '
|
||||||
'user_id INTEGER, user TEXT, agent_id INTEGER, agent_name TEXT, notify_action TEXT, '
|
'user_id INTEGER, user TEXT, notifier_id INTEGER, agent_id INTEGER, agent_name TEXT, notify_action TEXT, '
|
||||||
'subject_text TEXT, body_text TEXT, script_args TEXT, poster_url TEXT)'
|
'subject_text TEXT, body_text TEXT, poster_url TEXT)'
|
||||||
)
|
)
|
||||||
|
|
||||||
# library_sections table :: This table keeps record of the servers library sections
|
# library_sections table :: This table keeps record of the servers library sections
|
||||||
|
@ -899,6 +909,15 @@ def dbcheck():
|
||||||
'ALTER TABLE notify_log_temp RENAME TO notify_log'
|
'ALTER TABLE notify_log_temp RENAME TO notify_log'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Upgrade notify_log table from earlier versions
|
||||||
|
try:
|
||||||
|
c_db.execute('SELECT notifier_id FROM notify_log')
|
||||||
|
except sqlite3.OperationalError:
|
||||||
|
logger.debug(u"Altering database. Updating database table notify_log.")
|
||||||
|
c_db.execute(
|
||||||
|
'ALTER TABLE notify_log ADD COLUMN notifier_id INTEGER'
|
||||||
|
)
|
||||||
|
|
||||||
# Upgrade library_sections table from earlier versions (remove UNIQUE constraint on section_id)
|
# Upgrade library_sections table from earlier versions (remove UNIQUE constraint on section_id)
|
||||||
try:
|
try:
|
||||||
result = c_db.execute('SELECT SQL FROM sqlite_master WHERE type="table" AND name="library_sections"').fetchone()
|
result = c_db.execute('SELECT SQL FROM sqlite_master WHERE type="table" AND name="library_sections"').fetchone()
|
||||||
|
|
|
@ -74,35 +74,16 @@ class ActivityHandler(object):
|
||||||
|
|
||||||
session = self.get_live_session()
|
session = self.get_live_session()
|
||||||
|
|
||||||
# Check if any notification agents have notifications enabled
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
if any(d['on_play'] for d in notifiers.available_notification_agents()):
|
stream_data=session, notify_action='on_play'))
|
||||||
# Fire off notifications
|
|
||||||
threading.Thread(target=notification_handler.notify,
|
|
||||||
kwargs=dict(stream_data=session, notify_action='play')).start()
|
|
||||||
|
|
||||||
# Write the new session to our temp session table
|
# Write the new session to our temp session table
|
||||||
self.update_db_session(session=session)
|
self.update_db_session(session=session)
|
||||||
|
|
||||||
# Check if any notification agents have notifications enabled
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
if any(d['on_concurrent'] for d in notifiers.available_notification_agents()):
|
stream_data=session, notify_action='on_concurrent'))
|
||||||
# Check if any concurrent streams by the user
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
ip = True if plexpy.CONFIG.NOTIFY_CONCURRENT_BY_IP else None
|
stream_data=session, notify_action='on_newdevice'))
|
||||||
ap = activity_processor.ActivityProcessor()
|
|
||||||
user_sessions = ap.get_session_by_user_id(user_id=session['user_id'], ip_address=ip)
|
|
||||||
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()
|
|
||||||
|
|
||||||
# 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):
|
def on_stop(self, force_stop=False):
|
||||||
if self.is_valid_session():
|
if self.is_valid_session():
|
||||||
|
@ -123,11 +104,8 @@ class ActivityHandler(object):
|
||||||
# Retrieve the session data from our temp table
|
# Retrieve the session data from our temp table
|
||||||
db_session = ap.get_session_by_key(session_key=self.get_session_key())
|
db_session = ap.get_session_by_key(session_key=self.get_session_key())
|
||||||
|
|
||||||
# Check if any notification agents have notifications enabled
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
if any(d['on_stop'] for d in notifiers.available_notification_agents()):
|
stream_data=db_session, notify_action='on_stop'))
|
||||||
# Fire off notifications
|
|
||||||
threading.Thread(target=notification_handler.notify,
|
|
||||||
kwargs=dict(stream_data=db_session, notify_action='stop')).start()
|
|
||||||
|
|
||||||
# Write it to the history table
|
# Write it to the history table
|
||||||
monitor_proc = activity_processor.ActivityProcessor()
|
monitor_proc = activity_processor.ActivityProcessor()
|
||||||
|
@ -154,11 +132,8 @@ class ActivityHandler(object):
|
||||||
# Retrieve the session data from our temp table
|
# Retrieve the session data from our temp table
|
||||||
db_session = ap.get_session_by_key(session_key=self.get_session_key())
|
db_session = ap.get_session_by_key(session_key=self.get_session_key())
|
||||||
|
|
||||||
# Check if any notification agents have notifications enabled
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
if any(d['on_pause'] for d in notifiers.available_notification_agents()):
|
stream_data=db_session, notify_action='on_pause'))
|
||||||
# Fire off notifications
|
|
||||||
threading.Thread(target=notification_handler.notify,
|
|
||||||
kwargs=dict(stream_data=db_session, notify_action='pause')).start()
|
|
||||||
|
|
||||||
def on_resume(self):
|
def on_resume(self):
|
||||||
if self.is_valid_session():
|
if self.is_valid_session():
|
||||||
|
@ -176,11 +151,8 @@ class ActivityHandler(object):
|
||||||
# Retrieve the session data from our temp table
|
# Retrieve the session data from our temp table
|
||||||
db_session = ap.get_session_by_key(session_key=self.get_session_key())
|
db_session = ap.get_session_by_key(session_key=self.get_session_key())
|
||||||
|
|
||||||
# Check if any notification agents have notifications enabled
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
if any(d['on_resume'] for d in notifiers.available_notification_agents()):
|
stream_data=db_session, notify_action='on_resume'))
|
||||||
# Fire off notifications
|
|
||||||
threading.Thread(target=notification_handler.notify,
|
|
||||||
kwargs=dict(stream_data=db_session, notify_action='resume')).start()
|
|
||||||
|
|
||||||
def on_buffer(self):
|
def on_buffer(self):
|
||||||
if self.is_valid_session():
|
if self.is_valid_session():
|
||||||
|
@ -209,10 +181,8 @@ class ActivityHandler(object):
|
||||||
time_since_last_trigger == 0 or time_since_last_trigger >= plexpy.CONFIG.BUFFER_WAIT):
|
time_since_last_trigger == 0 or time_since_last_trigger >= plexpy.CONFIG.BUFFER_WAIT):
|
||||||
ap.set_session_buffer_trigger_time(session_key=self.get_session_key())
|
ap.set_session_buffer_trigger_time(session_key=self.get_session_key())
|
||||||
|
|
||||||
# Check if any notification agents have notifications enabled
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
if any(d['on_buffer'] for d in notifiers.available_notification_agents()):
|
stream_data=db_session, notify_action='on_buffer'))
|
||||||
threading.Thread(target=notification_handler.notify,
|
|
||||||
kwargs=dict(stream_data=db_stream, notify_action='buffer')).start()
|
|
||||||
|
|
||||||
# This function receives events from our websocket connection
|
# This function receives events from our websocket connection
|
||||||
def process(self):
|
def process(self):
|
||||||
|
@ -254,17 +224,9 @@ class ActivityHandler(object):
|
||||||
|
|
||||||
# Monitor if the stream has reached the watch percentage for notifications
|
# Monitor if the stream has reached the watch percentage for notifications
|
||||||
# The only purpose of this is for notifications
|
# The only purpose of this is for notifications
|
||||||
# Check if any notification agents have notifications enabled
|
if this_state != 'buffering':
|
||||||
notify_agents = [d['id'] for d in notifiers.available_notification_agents() if d['on_watched']]
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
# Get the current states for notifications from our db
|
stream_data=db_session, notify_action='on_watched'))
|
||||||
notified_agents = [d['agent_id'] for d in notification_handler.get_notify_state(session=db_session)
|
|
||||||
if d['notify_action'] == 'watched'] if notify_agents else []
|
|
||||||
|
|
||||||
if any(a not in notified_agents for a in notify_agents):
|
|
||||||
progress_percent = helpers.get_percent(self.timeline['viewOffset'], db_session['duration'])
|
|
||||||
if progress_percent >= plexpy.CONFIG.NOTIFY_WATCHED_PERCENT and this_state != 'buffering':
|
|
||||||
# Rather not put this on it's own thread so we know it completes before our next event.
|
|
||||||
notification_handler.notify(stream_data=db_session, notify_action='watched')
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# We don't have this session in our table yet, start a new one.
|
# We don't have this session in our table yet, start a new one.
|
||||||
|
|
|
@ -48,11 +48,9 @@ def check_active_sessions(ws_request=False):
|
||||||
if int_ping_count >= 3:
|
if int_ping_count >= 3:
|
||||||
logger.info(u"PlexPy Monitor :: The Plex Media Server is back up.")
|
logger.info(u"PlexPy Monitor :: The Plex Media Server is back up.")
|
||||||
|
|
||||||
# Check if any notification agents have notifications enabled
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
if any(d['on_intup'] for d in notifiers.available_notification_agents()):
|
notify_action='on_intup'))
|
||||||
# Fire off notifications
|
|
||||||
threading.Thread(target=notification_handler.notify_timeline,
|
|
||||||
kwargs=dict(notify_action='intup')).start()
|
|
||||||
int_ping_count = 0
|
int_ping_count = 0
|
||||||
|
|
||||||
media_container = session_list['sessions']
|
media_container = session_list['sessions']
|
||||||
|
@ -72,22 +70,14 @@ def check_active_sessions(ws_request=False):
|
||||||
if session['state'] == 'paused':
|
if session['state'] == 'paused':
|
||||||
logger.debug(u"PlexPy Monitor :: Session %s has been paused." % stream['session_key'])
|
logger.debug(u"PlexPy Monitor :: Session %s has been paused." % stream['session_key'])
|
||||||
|
|
||||||
# Check if any notification agents have notifications enabled
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
if any(d['on_pause'] for d in notifiers.available_notification_agents()):
|
stream_data=stream, notify_action='on_pause'))
|
||||||
# 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=stream, notify_action='pause')).start()
|
|
||||||
|
|
||||||
if session['state'] == 'playing' and stream['state'] == 'paused':
|
if session['state'] == 'playing' and stream['state'] == 'paused':
|
||||||
logger.debug(u"PlexPy Monitor :: Session %s has been resumed." % stream['session_key'])
|
logger.debug(u"PlexPy Monitor :: Session %s has been resumed." % stream['session_key'])
|
||||||
|
|
||||||
# Check if any notification agents have notifications enabled
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
if any(d['on_resume'] for d in notifiers.available_notification_agents()):
|
stream_data=stream, notify_action='on_resume'))
|
||||||
# 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=stream, notify_action='resume')).start()
|
|
||||||
|
|
||||||
if stream['state'] == 'paused' and not ws_request:
|
if stream['state'] == 'paused' and not ws_request:
|
||||||
# The stream is still paused so we need to increment the paused_counter
|
# The stream is still paused so we need to increment the paused_counter
|
||||||
|
@ -125,12 +115,9 @@ def check_active_sessions(ws_request=False):
|
||||||
'WHERE session_key = ? AND rating_key = ?',
|
'WHERE session_key = ? AND rating_key = ?',
|
||||||
[stream['session_key'], stream['rating_key']])
|
[stream['session_key'], stream['rating_key']])
|
||||||
|
|
||||||
# Check if any notification agents have notifications enabled
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
if any(d['on_buffer'] for d in notifiers.available_notification_agents()):
|
stream_data=stream, notify_action='on_buffer'))
|
||||||
# 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=stream, notify_action='buffer')).start()
|
|
||||||
else:
|
else:
|
||||||
# Subsequent buffer notifications after wait time
|
# Subsequent buffer notifications after wait time
|
||||||
if int(time.time()) > buffer_values[0]['buffer_last_triggered'] + \
|
if int(time.time()) > buffer_values[0]['buffer_last_triggered'] + \
|
||||||
|
@ -143,12 +130,8 @@ def check_active_sessions(ws_request=False):
|
||||||
'WHERE session_key = ? AND rating_key = ?',
|
'WHERE session_key = ? AND rating_key = ?',
|
||||||
[stream['session_key'], stream['rating_key']])
|
[stream['session_key'], stream['rating_key']])
|
||||||
|
|
||||||
# Check if any notification agents have notifications enabled
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
if any(d['on_buffer'] for d in notifiers.available_notification_agents()):
|
stream_data=stream, notify_action='on_buffer'))
|
||||||
# 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=stream, notify_action='buffer')).start()
|
|
||||||
|
|
||||||
logger.debug(u"PlexPy Monitor :: Session %s is buffering. Count is now %s. Last triggered %s."
|
logger.debug(u"PlexPy Monitor :: Session %s is buffering. Count is now %s. Last triggered %s."
|
||||||
% (stream['session_key'],
|
% (stream['session_key'],
|
||||||
|
@ -158,15 +141,8 @@ def check_active_sessions(ws_request=False):
|
||||||
# Check if the user has reached the offset in the media we defined as the "watched" percent
|
# Check if the user has reached the offset in the media we defined as the "watched" percent
|
||||||
# Don't trigger if state is buffer as some clients push the progress to the end when
|
# Don't trigger if state is buffer as some clients push the progress to the end when
|
||||||
# buffering on start.
|
# buffering on start.
|
||||||
if session['view_offset'] and session['duration'] and session['state'] != 'buffering':
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
if helpers.get_percent(session['view_offset'],
|
stream_data=stream, notify_action='on_watched'))
|
||||||
session['duration']) > plexpy.CONFIG.NOTIFY_WATCHED_PERCENT:
|
|
||||||
# Check if any notification agents have notifications enabled
|
|
||||||
if any(d['on_watched'] for d in notifiers.available_notification_agents()):
|
|
||||||
# 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=stream, notify_action='watched')).start()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# The user has stopped playing a stream
|
# The user has stopped playing a stream
|
||||||
|
@ -180,22 +156,11 @@ def check_active_sessions(ws_request=False):
|
||||||
'WHERE session_key = ? AND rating_key = ?',
|
'WHERE session_key = ? AND rating_key = ?',
|
||||||
[stream['stopped'], 'stopped', stream['session_key'], stream['rating_key']])
|
[stream['stopped'], 'stopped', stream['session_key'], stream['rating_key']])
|
||||||
|
|
||||||
# Check if the user has reached the offset in the media we defined as the "watched" percent
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
if stream['view_offset'] and stream['duration']:
|
stream_data=stream, notify_action='on_watched'))
|
||||||
if helpers.get_percent(stream['view_offset'],
|
|
||||||
stream['duration']) > plexpy.CONFIG.NOTIFY_WATCHED_PERCENT:
|
|
||||||
# Check if any notification agents have notifications enabled
|
|
||||||
if any(d['on_watched'] for d in notifiers.available_notification_agents()):
|
|
||||||
# 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=stream, notify_action='watched')).start()
|
|
||||||
|
|
||||||
# Check if any notification agents have notifications enabled
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
if any(d['on_stop'] for d in notifiers.available_notification_agents()):
|
stream_data=stream, notify_action='on_stop'))
|
||||||
# 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=stream, notify_action='stop')).start()
|
|
||||||
|
|
||||||
# Write the item history on playback stop
|
# Write the item history on playback stop
|
||||||
success = monitor_process.write_session_history(session=stream)
|
success = monitor_process.write_session_history(session=stream)
|
||||||
|
@ -247,11 +212,8 @@ def check_active_sessions(ws_request=False):
|
||||||
% str(int_ping_count))
|
% str(int_ping_count))
|
||||||
|
|
||||||
if int_ping_count == 3:
|
if int_ping_count == 3:
|
||||||
# Check if any notification agents have notifications enabled
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
if any(d['on_intdown'] for d in notifiers.available_notification_agents()):
|
notify_action='on_intdown'))
|
||||||
# Fire off notifications
|
|
||||||
threading.Thread(target=notification_handler.notify_timeline,
|
|
||||||
kwargs=dict(notify_action='intdown')).start()
|
|
||||||
|
|
||||||
|
|
||||||
def check_recently_added():
|
def check_recently_added():
|
||||||
|
@ -304,11 +266,8 @@ def check_recently_added():
|
||||||
if 0 < time_threshold - int(item['added_at']) <= time_interval:
|
if 0 < time_threshold - int(item['added_at']) <= time_interval:
|
||||||
logger.debug(u"PlexPy Monitor :: Library item %s has been added to Plex." % str(item['rating_key']))
|
logger.debug(u"PlexPy Monitor :: Library item %s has been added to Plex." % str(item['rating_key']))
|
||||||
|
|
||||||
# Check if any notification agents have notifications enabled
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
if any(d['on_created'] for d in notifiers.available_notification_agents()):
|
timeline_data=item, notify_action='on_created'))
|
||||||
# Fire off notifications
|
|
||||||
threading.Thread(target=notification_handler.notify_timeline,
|
|
||||||
kwargs=dict(timeline_data=item, notify_action='created')).start()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
item = max(metadata, key=lambda x:x['added_at'])
|
item = max(metadata, key=lambda x:x['added_at'])
|
||||||
|
@ -326,10 +285,9 @@ def check_recently_added():
|
||||||
logger.debug(u"PlexPy Monitor :: Library item %s has been added to Plex." % str(item['rating_key']))
|
logger.debug(u"PlexPy Monitor :: Library item %s has been added to Plex." % str(item['rating_key']))
|
||||||
|
|
||||||
# Check if any notification agents have notifications enabled
|
# Check if any notification agents have notifications enabled
|
||||||
if any(d['on_created'] for d in notifiers.available_notification_agents()):
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
# Fire off notifications
|
timeline_data=item, notify_action='on_created'))
|
||||||
threading.Thread(target=notification_handler.notify_timeline,
|
|
||||||
kwargs=dict(timeline_data=item, notify_action='created')).start()
|
|
||||||
|
|
||||||
def check_server_response():
|
def check_server_response():
|
||||||
|
|
||||||
|
@ -360,19 +318,14 @@ def check_server_response():
|
||||||
if ext_ping_count >= 3:
|
if ext_ping_count >= 3:
|
||||||
logger.info(u"PlexPy Monitor :: Plex remote access is back up.")
|
logger.info(u"PlexPy Monitor :: Plex remote access is back up.")
|
||||||
|
|
||||||
# Check if any notification agents have notifications enabled
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
if any(d['on_extup'] for d in notifiers.available_notification_agents()):
|
notify_action='on_extup'))
|
||||||
# Fire off notifications
|
|
||||||
threading.Thread(target=notification_handler.notify_timeline,
|
|
||||||
kwargs=dict(notify_action='extup')).start()
|
|
||||||
ext_ping_count = 0
|
ext_ping_count = 0
|
||||||
|
|
||||||
if ext_ping_count == 3:
|
if ext_ping_count == 3:
|
||||||
# Check if any notification agents have notifications enabled
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
if any(d['on_extdown'] for d in notifiers.available_notification_agents()):
|
notify_action='on_extdown'))
|
||||||
# Fire off notifications
|
|
||||||
threading.Thread(target=notification_handler.notify_timeline,
|
|
||||||
kwargs=dict(notify_action='extdown')).start()
|
|
||||||
|
|
||||||
|
|
||||||
def check_server_updates():
|
def check_server_updates():
|
||||||
|
@ -389,10 +342,8 @@ def check_server_updates():
|
||||||
if download_info['update_available']:
|
if download_info['update_available']:
|
||||||
logger.info(u"PlexPy Monitor :: PMS update available version: %s", download_info['version'])
|
logger.info(u"PlexPy Monitor :: PMS update available version: %s", download_info['version'])
|
||||||
|
|
||||||
# Check if any notification agents have notifications enabled
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
if any(d['on_pmsupdate'] for d in notifiers.available_notification_agents()):
|
notify_action='on_pmsupdate'))
|
||||||
# Fire off notifications
|
|
||||||
threading.Thread(target=notification_handler.notify_timeline,
|
|
||||||
kwargs=dict(notify_action='pmsupdate')).start()
|
|
||||||
else:
|
else:
|
||||||
logger.info(u"PlexPy Monitor :: No PMS update available.")
|
logger.info(u"PlexPy Monitor :: No PMS update available.")
|
|
@ -97,11 +97,10 @@ class ActivityProcessor(object):
|
||||||
|
|
||||||
if result == 'insert':
|
if result == 'insert':
|
||||||
# Check if any notification agents have notifications enabled
|
# Check if any notification agents have notifications enabled
|
||||||
if notify and any(d['on_play'] for d in notifiers.available_notification_agents()):
|
if notify:
|
||||||
values.update({'ip_address': session['ip_address']})
|
values.update({'ip_address': session['ip_address']})
|
||||||
# Push any notifications - Push it on it's own thread so we don't hold up our db actions
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
threading.Thread(target=notification_handler.notify,
|
stream_data=values, notify_action='on_play'))
|
||||||
kwargs=dict(stream_data=values, notify_action='play')).start()
|
|
||||||
|
|
||||||
# If it's our first write then time stamp it.
|
# If it's our first write then time stamp it.
|
||||||
started = int(time.time())
|
started = int(time.time())
|
||||||
|
@ -116,25 +115,11 @@ class ActivityProcessor(object):
|
||||||
ip_address = {'ip_address': ip_address}
|
ip_address = {'ip_address': ip_address}
|
||||||
self.db.upsert('sessions', ip_address, keys)
|
self.db.upsert('sessions', ip_address, keys)
|
||||||
|
|
||||||
# Check if any notification agents have notifications enabled
|
if notify:
|
||||||
if notify and any(d['on_concurrent'] for d in notifiers.available_notification_agents()):
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
# Check if any concurrent streams by the user
|
stream_data=values, notify_action='on_concurrent'))
|
||||||
user_sessions = self.get_session_by_user_id(user_id=session['user_id'],
|
plexpy.NOTIFY_QUEUE.put(notification_handler.add_to_notify_queue(
|
||||||
ip_address=plexpy.CONFIG.NOTIFY_CONCURRENT_BY_IP)
|
stream_data=values, notify_action='on_newdevice'))
|
||||||
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=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
|
return True
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -339,7 +339,7 @@ def get_notifiers(notifier_id=None, notify_action=None):
|
||||||
for item in result:
|
for item in result:
|
||||||
item['active'] = int(any([item.pop(k) for k in item.keys() if k in notify_actions]))
|
item['active'] = int(any([item.pop(k) for k in item.keys() if k in notify_actions]))
|
||||||
|
|
||||||
return sorted(result, key=lambda k: (k['agent_label'], k['id']))
|
return result
|
||||||
|
|
||||||
|
|
||||||
def delete_notifier(notifier_id=None):
|
def delete_notifier(notifier_id=None):
|
||||||
|
@ -357,7 +357,7 @@ def get_notifier_config(notifier_id=None):
|
||||||
if str(notifier_id).isdigit():
|
if str(notifier_id).isdigit():
|
||||||
notifier_id = int(notifier_id)
|
notifier_id = int(notifier_id)
|
||||||
else:
|
else:
|
||||||
logger.error(u"PlexPy Notifiers :: Unable to retrieve notifier config: invalid notifier_id.")
|
logger.error(u"PlexPy Notifiers :: Unable to retrieve notifier config: invalid notifier_id %s." % notifier_id)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
monitor_db = database.MonitorDatabase()
|
monitor_db = database.MonitorDatabase()
|
||||||
|
@ -381,7 +381,6 @@ def get_notifier_config(notifier_id=None):
|
||||||
notifier_text[k] = {'subject': result.pop(k + '_subject'),
|
notifier_text[k] = {'subject': result.pop(k + '_subject'),
|
||||||
'body': result.pop(k + '_body')}
|
'body': result.pop(k + '_body')}
|
||||||
|
|
||||||
result['agent'] = notifier_agent
|
|
||||||
result['config'] = notifier_config
|
result['config'] = notifier_config
|
||||||
result['actions'] = notifier_actions
|
result['actions'] = notifier_actions
|
||||||
result['notify_text'] = notifier_text
|
result['notify_text'] = notifier_text
|
||||||
|
@ -393,13 +392,13 @@ def add_notifier_config(agent_id=None, **kwargs):
|
||||||
if str(agent_id).isdigit():
|
if str(agent_id).isdigit():
|
||||||
agent_id = int(agent_id)
|
agent_id = int(agent_id)
|
||||||
else:
|
else:
|
||||||
logger.error(u"PlexPy Notifiers :: Unable to add new notifier: invalid agent_id.")
|
logger.error(u"PlexPy Notifiers :: Unable to add new notifier: invalid agent_id %s." % agent_id)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
agent = next((a for a in available_notification_agents() if a['id'] == agent_id), None)
|
agent = next((a for a in available_notification_agents() if a['id'] == agent_id), None)
|
||||||
|
|
||||||
if not agent:
|
if not agent:
|
||||||
logger.error(u"PlexPy Notifiers :: Unable to retrieve new notification agent: invalid agent_id.")
|
logger.error(u"PlexPy Notifiers :: Unable to retrieve new notification agent: invalid agent_id %s." % agent_id)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
keys = {'id': None}
|
keys = {'id': None}
|
||||||
|
@ -433,13 +432,13 @@ def set_notifier_config(notifier_id=None, agent_id=None, **kwargs):
|
||||||
if str(agent_id).isdigit():
|
if str(agent_id).isdigit():
|
||||||
agent_id = int(agent_id)
|
agent_id = int(agent_id)
|
||||||
else:
|
else:
|
||||||
logger.error(u"PlexPy Notifiers :: Unable to set exisiting notifier: invalid agent_id.")
|
logger.error(u"PlexPy Notifiers :: Unable to set exisiting notifier: invalid agent_id %s." % agent_id)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
agent = next((a for a in available_notification_agents() if a['id'] == agent_id), None)
|
agent = next((a for a in available_notification_agents() if a['id'] == agent_id), None)
|
||||||
|
|
||||||
if not agent:
|
if not agent:
|
||||||
logger.error(u"PlexPy Notifiers :: Unable to retrieve existing notification agent: invalid agent_id.")
|
logger.error(u"PlexPy Notifiers :: Unable to retrieve existing notification agent: invalid agent_id %s." % agent_id)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
notify_actions = get_notify_actions()
|
notify_actions = get_notify_actions()
|
||||||
|
@ -479,7 +478,7 @@ def set_notifier_config(notifier_id=None, agent_id=None, **kwargs):
|
||||||
def send_notification(notifier_id=None, subject='', body='', notify_action='', **kwargs):
|
def send_notification(notifier_id=None, subject='', body='', notify_action='', **kwargs):
|
||||||
notifier_config = get_notifier_config(notifier_id=notifier_id)
|
notifier_config = get_notifier_config(notifier_id=notifier_id)
|
||||||
if notifier_config:
|
if notifier_config:
|
||||||
agent = notifier_config['agent']
|
agent = get_agent_class(notifier_config['agent_id'])
|
||||||
return agent.notify(subject=subject,
|
return agent.notify(subject=subject,
|
||||||
body=body,
|
body=body,
|
||||||
action=notify_action,
|
action=notify_action,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue