Fix activity_pinger.py

This commit is contained in:
JonnyWong16 2023-03-07 16:50:12 -08:00
commit 2688449091
No known key found for this signature in database
GPG key ID: B1F1F9807184697A

View file

@ -99,22 +99,22 @@ def check_active_sessions(ws_request=False):
# Using the set config parameter as the interval, probably not the most accurate but # Using the set config parameter as the interval, probably not the most accurate but
# it will have to do for now. If it's a websocket request don't use this method. # it will have to do for now. If it's a websocket request don't use this method.
paused_counter = int(stream['paused_counter']) + plexpy.CONFIG.MONITORING_INTERVAL paused_counter = int(stream['paused_counter']) + plexpy.CONFIG.MONITORING_INTERVAL
monitor_db.action('UPDATE sessions SET paused_counter = ? ' monitor_db.action("UPDATE sessions SET paused_counter = ? "
'WHERE session_key = ? AND rating_key = ?', "WHERE session_key = ? AND rating_key = ?",
[paused_counter, stream['session_key'], stream['rating_key']]) [paused_counter, stream['session_key'], stream['rating_key']])
if session['state'] == 'buffering' and plexpy.CONFIG.BUFFER_THRESHOLD > 0: if session['state'] == 'buffering' and plexpy.CONFIG.BUFFER_THRESHOLD > 0:
# The stream is buffering so we need to increment the buffer_count # The stream is buffering so we need to increment the buffer_count
# We're going just increment on every monitor ping, # We're going just increment on every monitor ping,
# would be difficult to keep track otherwise # would be difficult to keep track otherwise
monitor_db.action('UPDATE sessions SET buffer_count = buffer_count + 1 ' monitor_db.action("UPDATE sessions SET buffer_count = buffer_count + 1 "
'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 the current buffer count and last buffer to determine if we should notify # Check the current buffer count and last buffer to determine if we should notify
buffer_values = monitor_db.select('SELECT buffer_count, buffer_last_triggered ' buffer_values = monitor_db.select("SELECT buffer_count, buffer_last_triggered "
'FROM sessions ' "FROM sessions "
'WHERE session_key = ? AND rating_key = ?', "WHERE session_key = ? AND rating_key = ?",
[stream['session_key'], stream['rating_key']]) [stream['session_key'], stream['rating_key']])
if buffer_values[0]['buffer_count'] >= plexpy.CONFIG.BUFFER_THRESHOLD: if buffer_values[0]['buffer_count'] >= plexpy.CONFIG.BUFFER_THRESHOLD:
@ -125,9 +125,9 @@ def check_active_sessions(ws_request=False):
logger.info("Tautulli Monitor :: User '%s' has triggered a buffer warning." logger.info("Tautulli Monitor :: User '%s' has triggered a buffer warning."
% stream['user']) % stream['user'])
# Set the buffer trigger time # Set the buffer trigger time
monitor_db.action('UPDATE sessions ' monitor_db.action("UPDATE sessions "
'SET buffer_last_triggered = strftime("%s","now") ' "SET buffer_last_triggered = strftime('%s', 'now') "
'WHERE session_key = ? AND rating_key = ?', "WHERE session_key = ? AND rating_key = ?",
[stream['session_key'], stream['rating_key']]) [stream['session_key'], stream['rating_key']])
plexpy.NOTIFY_QUEUE.put({'stream_data': stream.copy(), 'notify_action': 'on_buffer'}) plexpy.NOTIFY_QUEUE.put({'stream_data': stream.copy(), 'notify_action': 'on_buffer'})
@ -139,9 +139,9 @@ def check_active_sessions(ws_request=False):
logger.info("Tautulli Monitor :: User '%s' has triggered multiple buffer warnings." logger.info("Tautulli Monitor :: User '%s' has triggered multiple buffer warnings."
% stream['user']) % stream['user'])
# Set the buffer trigger time # Set the buffer trigger time
monitor_db.action('UPDATE sessions ' monitor_db.action("UPDATE sessions "
'SET buffer_last_triggered = strftime("%s","now") ' "SET buffer_last_triggered = strftime('%s', 'now') "
'WHERE session_key = ? AND rating_key = ?', "WHERE session_key = ? AND rating_key = ?",
[stream['session_key'], stream['rating_key']]) [stream['session_key'], stream['rating_key']])
plexpy.NOTIFY_QUEUE.put({'stream_data': stream.copy(), 'notify_action': 'on_buffer'}) plexpy.NOTIFY_QUEUE.put({'stream_data': stream.copy(), 'notify_action': 'on_buffer'})
@ -171,8 +171,8 @@ def check_active_sessions(ws_request=False):
if not stream['stopped']: if not stream['stopped']:
# Set the stream stop time # Set the stream stop time
stream['stopped'] = helpers.timestamp() stream['stopped'] = helpers.timestamp()
monitor_db.action('UPDATE sessions SET stopped = ?, state = ? ' monitor_db.action("UPDATE sessions SET stopped = ?, state = ? "
'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']])
progress_percent = helpers.get_percent(stream['view_offset'], stream['duration']) progress_percent = helpers.get_percent(stream['view_offset'], stream['duration'])