mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-08 06:00:51 -07:00
Another attempt at using websockets for recently added
This commit is contained in:
parent
438e525319
commit
8ed2f0eafa
4 changed files with 33 additions and 20 deletions
|
@ -42,7 +42,7 @@ DOCUMENTATION :: END
|
||||||
<td>${arrow.get(next_run_interval).format('HH:mm:ss')}</td>
|
<td>${arrow.get(next_run_interval).format('HH:mm:ss')}</td>
|
||||||
<td>${arrow.get(sched_job.next_run_time).format('YYYY-MM-DD HH:mm:ss')}</td>
|
<td>${arrow.get(sched_job.next_run_time).format('YYYY-MM-DD HH:mm:ss')}</td>
|
||||||
</tr>
|
</tr>
|
||||||
% elif job == 'Check for active sessions' and plexpy.CONFIG.MONITORING_USE_WEBSOCKET and not plexpy.POLLING_FAILOVER:
|
% elif job in ('Check for active sessions', 'Check for recently added items') and plexpy.CONFIG.MONITORING_USE_WEBSOCKET and not plexpy.POLLING_FAILOVER:
|
||||||
<tr>
|
<tr>
|
||||||
<td>${job}</td>
|
<td>${job}</td>
|
||||||
<td><i class="fa fa-sm fa-fw fa-check"></i> Using Websocket</td>
|
<td><i class="fa fa-sm fa-fw fa-check"></i> Using Websocket</td>
|
||||||
|
|
|
@ -308,8 +308,6 @@ def initialize_scheduler():
|
||||||
schedule_job(pmsconnect.get_server_friendly_name, 'Refresh Plex server name',
|
schedule_job(pmsconnect.get_server_friendly_name, 'Refresh Plex server name',
|
||||||
hours=12, minutes=0, seconds=0)
|
hours=12, minutes=0, seconds=0)
|
||||||
|
|
||||||
schedule_job(activity_pinger.check_recently_added, 'Check for recently added items',
|
|
||||||
hours=0, minutes=0, seconds=monitor_seconds * bool(CONFIG.NOTIFY_RECENTLY_ADDED))
|
|
||||||
schedule_job(activity_pinger.check_server_response, 'Check for Plex remote access',
|
schedule_job(activity_pinger.check_server_response, 'Check for Plex remote access',
|
||||||
hours=0, minutes=0, seconds=monitor_seconds * bool(CONFIG.MONITOR_REMOTE_ACCESS))
|
hours=0, minutes=0, seconds=monitor_seconds * bool(CONFIG.MONITOR_REMOTE_ACCESS))
|
||||||
schedule_job(activity_pinger.check_server_updates, 'Check for Plex updates',
|
schedule_job(activity_pinger.check_server_updates, 'Check for Plex updates',
|
||||||
|
@ -319,6 +317,8 @@ def initialize_scheduler():
|
||||||
if not CONFIG.MONITORING_USE_WEBSOCKET or POLLING_FAILOVER:
|
if not CONFIG.MONITORING_USE_WEBSOCKET or POLLING_FAILOVER:
|
||||||
schedule_job(activity_pinger.check_active_sessions, 'Check for active sessions',
|
schedule_job(activity_pinger.check_active_sessions, 'Check for active sessions',
|
||||||
hours=0, minutes=0, seconds=monitor_seconds)
|
hours=0, minutes=0, seconds=monitor_seconds)
|
||||||
|
schedule_job(activity_pinger.check_recently_added, 'Check for recently added items',
|
||||||
|
hours=0, minutes=0, seconds=monitor_seconds * bool(CONFIG.NOTIFY_RECENTLY_ADDED))
|
||||||
|
|
||||||
# Refresh the users list and libraries list
|
# Refresh the users list and libraries list
|
||||||
user_hours = CONFIG.REFRESH_USERS_INTERVAL if 1 <= CONFIG.REFRESH_USERS_INTERVAL <= 24 else 12
|
user_hours = CONFIG.REFRESH_USERS_INTERVAL if 1 <= CONFIG.REFRESH_USERS_INTERVAL <= 24 else 12
|
||||||
|
|
|
@ -26,6 +26,8 @@ import notifiers
|
||||||
import pmsconnect
|
import pmsconnect
|
||||||
|
|
||||||
|
|
||||||
|
RECENTLY_ADDED_WAITLIST = []
|
||||||
|
|
||||||
class ActivityHandler(object):
|
class ActivityHandler(object):
|
||||||
|
|
||||||
def __init__(self, timeline):
|
def __init__(self, timeline):
|
||||||
|
@ -84,7 +86,7 @@ class ActivityHandler(object):
|
||||||
|
|
||||||
def on_stop(self, force_stop=False):
|
def on_stop(self, force_stop=False):
|
||||||
if self.is_valid_session():
|
if self.is_valid_session():
|
||||||
logger.debug(u"PlexPy ActivityHandler :: Session %s has stopped." % str(self.get_session_key()))
|
logger.debug(u"PlexPy ActivityHandler :: Session %s stopped." % str(self.get_session_key()))
|
||||||
|
|
||||||
# Set the session last_paused timestamp
|
# Set the session last_paused timestamp
|
||||||
ap = activity_processor.ActivityProcessor()
|
ap = activity_processor.ActivityProcessor()
|
||||||
|
@ -258,23 +260,34 @@ class TimelineHandler(object):
|
||||||
|
|
||||||
def on_created(self):
|
def on_created(self):
|
||||||
if self.is_item():
|
if self.is_item():
|
||||||
logger.debug(u"PlexPy TimelineHandler :: Library item %s has been added to Plex." % str(self.get_rating_key()))
|
logger.debug(u"PlexPy TimelineHandler :: Library item %s added to Plex." % str(self.get_rating_key()))
|
||||||
|
metadata = self.get_metadata()
|
||||||
|
|
||||||
# Fire off notifications
|
plexpy.NOTIFY_QUEUE.put({'timeline_data': metadata, 'notify_action': 'on_created'})
|
||||||
threading.Thread(target=notification_handler.notify_timeline,
|
|
||||||
kwargs=dict(timeline_data=self.get_metadata(), notify_action='created')).start()
|
|
||||||
|
|
||||||
# This function receives events from our websocket connection
|
# This function receives events from our websocket connection
|
||||||
def process(self):
|
def process(self):
|
||||||
if self.is_item():
|
if self.is_item():
|
||||||
|
|
||||||
|
rating_key = self.get_rating_key()
|
||||||
|
|
||||||
this_state = self.timeline['state']
|
this_state = self.timeline['state']
|
||||||
this_type = self.timeline['type']
|
this_type = self.timeline['type']
|
||||||
|
this_section = self.timeline['sectionID']
|
||||||
this_metadataState = self.timeline.get('metadataState', None)
|
this_metadataState = self.timeline.get('metadataState', None)
|
||||||
this_mediaState = self.timeline.get('mediaState', None)
|
|
||||||
|
|
||||||
# state: 5: done processing metadata
|
# state: 0: created media, 5: done processing metadata
|
||||||
# type: 1: movie, 2: tv show, 4: episode, 8: artist, 10: track
|
# type: 1: movie, 2: tv show, 4: episode, 8: artist, 10: track
|
||||||
types = [1, 2, 4, 8, 10]
|
if plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_GRANDPARENT:
|
||||||
if this_state == 5 and this_type in types and this_metadataState == None and this_mediaState == None:
|
media_types = (1, 2, 8)
|
||||||
|
else:
|
||||||
|
media_types = (1, 4, 10)
|
||||||
|
|
||||||
|
if this_state == 0 and this_type in media_types and this_section > 0 and this_metadataState == "created":
|
||||||
|
logger.debug(u"PlexPy TimelineHandler :: Library item %s added to recently added queue." % str(rating_key))
|
||||||
|
RECENTLY_ADDED_WAITLIST.append(rating_key)
|
||||||
|
|
||||||
|
if this_state == 5 and this_type in media_types and this_section > 0 and rating_key in RECENTLY_ADDED_WAITLIST:
|
||||||
|
logger.debug(u"PlexPy TimelineHandler :: Library item %s done processing metadata." % str(rating_key))
|
||||||
|
RECENTLY_ADDED_WAITLIST.remove(rating_key)
|
||||||
self.on_created()
|
self.on_created()
|
|
@ -163,14 +163,14 @@ def process(opcode, data):
|
||||||
activity = activity_handler.ActivityHandler(timeline=time_line[0])
|
activity = activity_handler.ActivityHandler(timeline=time_line[0])
|
||||||
activity.process()
|
activity.process()
|
||||||
|
|
||||||
#if type == 'timeline':
|
if type == 'timeline':
|
||||||
# try:
|
try:
|
||||||
# time_line = info.get('_children')
|
time_line = info.get('_children')
|
||||||
# except:
|
except:
|
||||||
# logger.debug(u"PlexPy WebSocket :: Timeline event found but unable to get timeline data.")
|
logger.debug(u"PlexPy WebSocket :: Timeline event found but unable to get timeline data.")
|
||||||
# return False
|
return False
|
||||||
|
|
||||||
# activity = activity_handler.TimelineHandler(timeline=time_line[0])
|
activity = activity_handler.TimelineHandler(timeline=time_line[0])
|
||||||
# activity.process()
|
activity.process()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue