mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 07:22:37 -07:00
Add method to check if a stream is a continued session
This commit is contained in:
parent
ecfc3ed74f
commit
3ff0b4a256
4 changed files with 51 additions and 10 deletions
|
@ -142,15 +142,20 @@ class ActivityProcessor(object):
|
|||
result = self.db.upsert('sessions', values, keys)
|
||||
|
||||
if result == 'insert':
|
||||
# Check if any notification agents have notifications enabled
|
||||
if notify:
|
||||
plexpy.NOTIFY_QUEUE.put({'stream_data': values.copy(), 'notify_action': 'on_play'})
|
||||
|
||||
# If it's our first write then time stamp it.
|
||||
started = int(time.time())
|
||||
timestamp = {'started': started}
|
||||
continued_session = self.is_continued_session(user_id=values['user_id'],
|
||||
machine_id=values['machine_id'],
|
||||
media_type=values['media_type'],
|
||||
started=started)
|
||||
timestamp = {'started': started, 'continued_session': continued_session}
|
||||
self.db.upsert('sessions', timestamp, keys)
|
||||
|
||||
# Check if any notification agents have notifications enabled
|
||||
if notify:
|
||||
session.update(timestamp)
|
||||
plexpy.NOTIFY_QUEUE.put({'stream_data': session.copy(), 'notify_action': 'on_play'})
|
||||
|
||||
# Add Live TV library if it hasn't been added
|
||||
if values['live']:
|
||||
libraries.add_live_tv_library()
|
||||
|
@ -199,6 +204,12 @@ class ActivityProcessor(object):
|
|||
state='stopped',
|
||||
stopped=stopped)
|
||||
|
||||
if not is_import:
|
||||
self.write_continued_session(user_id=session['user_id'],
|
||||
machine_id=session['machine_id'],
|
||||
media_type=session['media_type'],
|
||||
stopped=stopped)
|
||||
|
||||
if str(session['rating_key']).isdigit() and session['media_type'] in ('movie', 'episode', 'track'):
|
||||
logging_enabled = True
|
||||
else:
|
||||
|
@ -630,3 +641,16 @@ class ActivityProcessor(object):
|
|||
self.db.action('UPDATE sessions SET watched = ?'
|
||||
'WHERE session_key = ?',
|
||||
[1, session_key])
|
||||
|
||||
def write_continued_session(self, user_id=None, machine_id=None, media_type=None, stopped=None):
|
||||
keys = {'user_id': user_id, 'machine_id': machine_id, 'media_type': media_type}
|
||||
values = {'stopped': stopped}
|
||||
self.db.upsert(table_name='sessions_continued', key_dict=keys, value_dict=values)
|
||||
|
||||
def is_continued_session(self, user_id=None, machine_id=None, media_type=None, started=None):
|
||||
last_session = self.db.select_single('SELECT stopped '
|
||||
'FROM sessions_continued '
|
||||
'WHERE user_id = ? AND machine_id = ? AND media_type = ? '
|
||||
'ORDER BY stopped DESC',
|
||||
[user_id, machine_id, media_type])
|
||||
return int(started - last_session.get('stopped', 0) < plexpy.CONFIG.NOTIFY_CONTINUED_SESSION_THRESHOLD)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue