mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-08 14:10:52 -07:00
Switch recently added to only use activity pinger
* Fixed activity pinger logic for grouping notifications
This commit is contained in:
parent
53044c75dd
commit
69a3b5134f
5 changed files with 56 additions and 50 deletions
|
@ -285,13 +285,13 @@ def initialize_scheduler():
|
||||||
hours=12, minutes=0, seconds=0)
|
hours=12, minutes=0, seconds=0)
|
||||||
schedule_job(pmsconnect.PmsConnect().get_server_friendly_name, 'Refresh Plex Server Name',
|
schedule_job(pmsconnect.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=seconds)
|
||||||
|
|
||||||
# If we're not using websockets then fall back to polling
|
# If we're not using websockets then fall back to polling
|
||||||
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=seconds)
|
hours=0, minutes=0, seconds=seconds)
|
||||||
schedule_job(activity_pinger.check_recently_added, 'Check for recently added items',
|
|
||||||
hours=0, minutes=0, seconds=seconds)
|
|
||||||
|
|
||||||
# Refresh the users list
|
# Refresh the users list
|
||||||
if CONFIG.REFRESH_USERS_INTERVAL:
|
if CONFIG.REFRESH_USERS_INTERVAL:
|
||||||
|
|
|
@ -218,7 +218,7 @@ class TimelineHandler(object):
|
||||||
|
|
||||||
def __init__(self, timeline):
|
def __init__(self, timeline):
|
||||||
self.timeline = timeline
|
self.timeline = timeline
|
||||||
logger.debug(timeline)
|
#logger.debug(timeline)
|
||||||
|
|
||||||
def is_item(self):
|
def is_item(self):
|
||||||
if 'itemID' in self.timeline:
|
if 'itemID' in self.timeline:
|
||||||
|
|
|
@ -167,7 +167,10 @@ def check_active_sessions(ws_request=False):
|
||||||
def check_recently_added():
|
def check_recently_added():
|
||||||
|
|
||||||
with monitor_lock:
|
with monitor_lock:
|
||||||
current_time = int(time.time())
|
# add delay to allow for metadata processing
|
||||||
|
delay = plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_DELAY
|
||||||
|
time_threshold = int(time.time()) - delay
|
||||||
|
time_interval = plexpy.CONFIG.MONITORING_INTERVAL
|
||||||
|
|
||||||
pms_connect = pmsconnect.PmsConnect()
|
pms_connect = pmsconnect.PmsConnect()
|
||||||
recently_added_list = pms_connect.get_recently_added_details(count='10')
|
recently_added_list = pms_connect.get_recently_added_details(count='10')
|
||||||
|
@ -176,35 +179,42 @@ def check_recently_added():
|
||||||
recently_added = recently_added_list['recently_added']
|
recently_added = recently_added_list['recently_added']
|
||||||
|
|
||||||
for item in recently_added:
|
for item in recently_added:
|
||||||
if int(item['added_at']) >= current_time - plexpy.CONFIG.MONITORING_INTERVAL:
|
|
||||||
if item['media_type'] == 'movie':
|
if item['media_type'] == 'movie':
|
||||||
metadata_list = pms_connect.get_metadata_details(item['rating_key'])
|
metadata_list = pms_connect.get_metadata_details(item['rating_key'])
|
||||||
if metadata_list:
|
if metadata_list:
|
||||||
metadata = [metadata_list['metadata']]
|
metadata = [metadata_list['metadata']]
|
||||||
else:
|
else:
|
||||||
logger.error(u"PlexPy Monitor :: Unable to retrieve metadata for rating_key %s" % str(item['rating_key']))
|
logger.error(u"PlexPy Monitor :: Unable to retrieve metadata for rating_key %s" \
|
||||||
|
% str(item['rating_key']))
|
||||||
elif plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_GRANDPARENT:
|
|
||||||
metadata_list = pms_connect.get_metadata_details(item['parent_rating_key'])
|
|
||||||
if metadata_list:
|
|
||||||
metadata = [metadata_list['metadata']]
|
|
||||||
else:
|
|
||||||
logger.error(u"PlexPy Monitor :: Unable to retrieve metadata for parent_rating_key %s" % str(item['parent_rating_key']))
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
metadata_list = pms_connect.get_metadata_children_details(item['rating_key'])
|
metadata_list = pms_connect.get_metadata_children_details(item['rating_key'])
|
||||||
if metadata_list:
|
if metadata_list:
|
||||||
metadata = metadata_list['metadata']
|
metadata = metadata_list['metadata']
|
||||||
else:
|
else:
|
||||||
logger.error(u"PlexPy Monitor :: Unable to retrieve children metadata for rating_key" % str(item['rating_key']))
|
logger.error(u"PlexPy Monitor :: Unable to retrieve children metadata for rating_key %s" \
|
||||||
|
% str(item['rating_key']))
|
||||||
|
|
||||||
if metadata:
|
if metadata:
|
||||||
|
if not plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_GRANDPARENT:
|
||||||
for item in metadata:
|
for item in metadata:
|
||||||
if (plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_GRANDPARENT \
|
if 0 < int(item['added_at']) - time_threshold <= time_interval:
|
||||||
and int(item['updated_at']) >= current_time - plexpy.CONFIG.MONITORING_INTERVAL) \
|
# Fire off notifications
|
||||||
or (not plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_GRANDPARENT \
|
threading.Thread(target=notification_handler.notify_timeline,
|
||||||
and int(item['added_at']) >= current_time - plexpy.CONFIG.MONITORING_INTERVAL):
|
kwargs=dict(timeline_data=item, notify_action='created')).start()
|
||||||
logger.debug(u"PlexPy Monitor :: Library item %s has been added to Plex." % str(item['rating_key']))
|
|
||||||
|
else:
|
||||||
|
item = max(metadata, key=lambda x:x['added_at'])
|
||||||
|
|
||||||
|
if 0 < int(item['added_at']) - time_threshold <= time_interval:
|
||||||
|
if item['media_type'] == 'episode' or item['media_type'] == 'track':
|
||||||
|
metadata_list = pms_connect.get_metadata_details(item['grandparent_rating_key'])
|
||||||
|
|
||||||
|
if metadata_list:
|
||||||
|
item = metadata_list['metadata']
|
||||||
|
else:
|
||||||
|
logger.error(u"PlexPy Monitor :: Unable to retrieve grandparent metadata for grandparent_rating_key %s" \
|
||||||
|
% str(item['rating_key']))
|
||||||
|
|
||||||
# Fire off notifications
|
# Fire off notifications
|
||||||
threading.Thread(target=notification_handler.notify_timeline,
|
threading.Thread(target=notification_handler.notify_timeline,
|
||||||
|
|
|
@ -172,10 +172,6 @@ def notify_timeline(timeline_data=None, notify_action=None):
|
||||||
if timeline_data and notify_action:
|
if timeline_data and notify_action:
|
||||||
for agent in notifiers.available_notification_agents():
|
for agent in notifiers.available_notification_agents():
|
||||||
if agent['on_created'] and notify_action == 'created':
|
if agent['on_created'] and notify_action == 'created':
|
||||||
if (plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_GRANDPARENT \
|
|
||||||
and (timeline_data['media_type'] == 'movie' or timeline_data['media_type'] == 'show' or timeline_data['media_type'] == 'artist')) \
|
|
||||||
or (not plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_GRANDPARENT \
|
|
||||||
and (timeline_data['media_type'] == 'movie' or timeline_data['media_type'] == 'episode' or timeline_data['media_type'] == 'track')):
|
|
||||||
# Build and send notification
|
# Build and send notification
|
||||||
notify_strings = build_notify_text(timeline=timeline_data, state=notify_action)
|
notify_strings = build_notify_text(timeline=timeline_data, state=notify_action)
|
||||||
notifiers.send_notification(config_id=agent['id'],
|
notifiers.send_notification(config_id=agent['id'],
|
||||||
|
|
|
@ -139,14 +139,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