mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-08 06:00:51 -07:00
Update websocket and handler for timeline events
This commit is contained in:
parent
32cf1ada8b
commit
1c58a47073
2 changed files with 58 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
||||||
# This file is part of PlexPy.
|
# This file is part of PlexPy.
|
||||||
#
|
#
|
||||||
# PlexPy is free software: you can redistribute it and/or modify
|
# PlexPy is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -212,4 +212,49 @@ class ActivityHandler(object):
|
||||||
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.
|
||||||
if this_state != 'buffering':
|
if this_state != 'buffering':
|
||||||
self.on_start()
|
self.on_start()
|
||||||
|
|
||||||
|
class TimelineHandler(object):
|
||||||
|
|
||||||
|
def __init__(self, timeline):
|
||||||
|
self.timeline = timeline
|
||||||
|
# print timeline
|
||||||
|
|
||||||
|
def is_item(self):
|
||||||
|
if 'itemID' in self.timeline and 'metadataState' in self.timeline:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
def get_rating_key(self):
|
||||||
|
if self.is_item():
|
||||||
|
return int(self.timeline['itemID'])
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_metadata(self):
|
||||||
|
pms_connect = pmsconnect.PmsConnect()
|
||||||
|
metadata_list = pms_connect.get_metadata_details(self.get_rating_key())
|
||||||
|
|
||||||
|
if metadata_list:
|
||||||
|
return metadata_list['metadata']
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def on_created(self):
|
||||||
|
if self.is_item():
|
||||||
|
logger.debug(u"PlexPy TimelineHandler :: Library item %s has been added to Plex." % str(self.get_rating_key()))
|
||||||
|
|
||||||
|
# Fire off notifications
|
||||||
|
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
|
||||||
|
def process(self):
|
||||||
|
if self.is_item():
|
||||||
|
|
||||||
|
this_state = self.timeline['state']
|
||||||
|
this_metadataState = self.timeline['metadataState']
|
||||||
|
|
||||||
|
if this_state == 0 and this_metadataState == 'created':
|
||||||
|
self.on_created()
|
|
@ -1,4 +1,4 @@
|
||||||
# This file is part of PlexPy.
|
# This file is part of PlexPy.
|
||||||
#
|
#
|
||||||
# PlexPy is free software: you can redistribute it and/or modify
|
# PlexPy is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -139,4 +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':
|
||||||
|
try:
|
||||||
|
time_line = info.get('_children')
|
||||||
|
except:
|
||||||
|
logger.debug(u"PlexPy WebSocket :: Timeline event found but unable to get timeline data.")
|
||||||
|
return False
|
||||||
|
|
||||||
|
activity = activity_handler.TimelineHandler(timeline=time_line[0])
|
||||||
|
activity.process()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue