mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-08 06:00:51 -07:00
Merge branch 'nightly' into python3
# Conflicts: # data/interfaces/default/current_activity_instance.html # plexpy/activity_handler.py # plexpy/graphs.py # plexpy/helpers.py # plexpy/pmsconnect.py # plexpy/version.py # plexpy/webserve.py
This commit is contained in:
commit
8d5bc88fd9
75 changed files with 2227 additions and 794 deletions
|
@ -66,6 +66,9 @@ class ActivityProcessor(object):
|
|||
'platform': session.get('platform', ''),
|
||||
'parent_rating_key': session.get('parent_rating_key', ''),
|
||||
'grandparent_rating_key': session.get('grandparent_rating_key', ''),
|
||||
'originally_available_at': session.get('originally_available_at', ''),
|
||||
'added_at': session.get('added_at', ''),
|
||||
'guid': session.get('guid', ''),
|
||||
'view_offset': session.get('view_offset', ''),
|
||||
'duration': session.get('duration', ''),
|
||||
'video_decision': session.get('video_decision', ''),
|
||||
|
@ -130,6 +133,9 @@ class ActivityProcessor(object):
|
|||
'relayed': session.get('relayed', 0),
|
||||
'rating_key_websocket': session.get('rating_key_websocket', ''),
|
||||
'raw_stream_info': json.dumps(session),
|
||||
'channel_call_sign': session.get('channel_call_sign', ''),
|
||||
'channel_identifier': session.get('channel_identifier', ''),
|
||||
'channel_thumb': session.get('channel_thumb', ''),
|
||||
'stopped': int(time.time())
|
||||
}
|
||||
|
||||
|
@ -148,6 +154,10 @@ class ActivityProcessor(object):
|
|||
timestamp = {'started': started}
|
||||
self.db.upsert('sessions', timestamp, keys)
|
||||
|
||||
# Add Live TV library if it hasn't been added
|
||||
if values['live']:
|
||||
libraries.add_live_tv_library()
|
||||
|
||||
return True
|
||||
|
||||
def write_session_history(self, session=None, import_metadata=None, is_import=False, import_ignore_interval=0):
|
||||
|
@ -240,7 +250,12 @@ class ActivityProcessor(object):
|
|||
if not is_import:
|
||||
logger.debug("Tautulli ActivityProcessor :: Fetching metadata for item ratingKey %s" % session['rating_key'])
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
metadata = pms_connect.get_metadata_details(rating_key=str(session['rating_key']))
|
||||
if session['live']:
|
||||
metadata = pms_connect.get_metadata_details(rating_key=str(session['rating_key']),
|
||||
cache_key=session['session_key'],
|
||||
return_cache=True)
|
||||
else:
|
||||
metadata = pms_connect.get_metadata_details(rating_key=str(session['rating_key']))
|
||||
if not metadata:
|
||||
return False
|
||||
else:
|
||||
|
@ -284,38 +299,57 @@ class ActivityProcessor(object):
|
|||
# % session['session_key'])
|
||||
self.db.upsert(table_name='session_history', key_dict=keys, value_dict=values)
|
||||
|
||||
# Check if we should group the session, select the last two rows from the user
|
||||
query = 'SELECT id, rating_key, view_offset, user_id, reference_id FROM session_history ' \
|
||||
'WHERE user_id = ? AND rating_key = ? ORDER BY id DESC LIMIT 2 '
|
||||
|
||||
args = [session['user_id'], session['rating_key']]
|
||||
|
||||
result = self.db.select(query=query, args=args)
|
||||
|
||||
new_session = prev_session = None
|
||||
prev_progress_percent = media_watched_percent = 0
|
||||
# Get the last insert row id
|
||||
last_id = self.db.last_insert_id()
|
||||
new_session = prev_session = None
|
||||
prev_progress_percent = media_watched_percent = 0
|
||||
|
||||
if len(result) > 1:
|
||||
new_session = {'id': result[0]['id'],
|
||||
'rating_key': result[0]['rating_key'],
|
||||
'view_offset': result[0]['view_offset'],
|
||||
'user_id': result[0]['user_id'],
|
||||
'reference_id': result[0]['reference_id']}
|
||||
if session['live']:
|
||||
# Check if we should group the session, select the last guid from the user
|
||||
query = 'SELECT session_history.id, session_history_metadata.guid, session_history.reference_id ' \
|
||||
'FROM session_history ' \
|
||||
'JOIN session_history_metadata ON session_history.id == session_history_metadata.id ' \
|
||||
'WHERE session_history.user_id = ? ORDER BY session_history.id DESC LIMIT 1 '
|
||||
|
||||
prev_session = {'id': result[1]['id'],
|
||||
'rating_key': result[1]['rating_key'],
|
||||
'view_offset': result[1]['view_offset'],
|
||||
'user_id': result[1]['user_id'],
|
||||
'reference_id': result[1]['reference_id']}
|
||||
args = [session['user_id']]
|
||||
|
||||
watched_percent = {'movie': plexpy.CONFIG.MOVIE_WATCHED_PERCENT,
|
||||
'episode': plexpy.CONFIG.TV_WATCHED_PERCENT,
|
||||
'track': plexpy.CONFIG.MUSIC_WATCHED_PERCENT
|
||||
}
|
||||
prev_progress_percent = helpers.get_percent(prev_session['view_offset'], session['duration'])
|
||||
media_watched_percent = watched_percent.get(session['media_type'], 0)
|
||||
result = self.db.select(query=query, args=args)
|
||||
|
||||
if len(result) > 0:
|
||||
new_session = {'id': last_id,
|
||||
'guid': metadata['guid'],
|
||||
'reference_id': last_id}
|
||||
|
||||
prev_session = {'id': result[0]['id'],
|
||||
'guid': result[0]['guid'],
|
||||
'reference_id': result[0]['reference_id']}
|
||||
|
||||
else:
|
||||
# Check if we should group the session, select the last two rows from the user
|
||||
query = 'SELECT id, rating_key, view_offset, reference_id FROM session_history ' \
|
||||
'WHERE user_id = ? AND rating_key = ? ORDER BY id DESC LIMIT 2 '
|
||||
|
||||
args = [session['user_id'], session['rating_key']]
|
||||
|
||||
result = self.db.select(query=query, args=args)
|
||||
|
||||
if len(result) > 1:
|
||||
new_session = {'id': result[0]['id'],
|
||||
'rating_key': result[0]['rating_key'],
|
||||
'view_offset': result[0]['view_offset'],
|
||||
'reference_id': result[0]['reference_id']}
|
||||
|
||||
prev_session = {'id': result[1]['id'],
|
||||
'rating_key': result[1]['rating_key'],
|
||||
'view_offset': result[1]['view_offset'],
|
||||
'reference_id': result[1]['reference_id']}
|
||||
|
||||
watched_percent = {'movie': plexpy.CONFIG.MOVIE_WATCHED_PERCENT,
|
||||
'episode': plexpy.CONFIG.TV_WATCHED_PERCENT,
|
||||
'track': plexpy.CONFIG.MUSIC_WATCHED_PERCENT
|
||||
}
|
||||
prev_progress_percent = helpers.get_percent(prev_session['view_offset'], session['duration'])
|
||||
media_watched_percent = watched_percent.get(session['media_type'], 0)
|
||||
|
||||
query = 'UPDATE session_history SET reference_id = ? WHERE id = ? '
|
||||
|
||||
|
@ -326,7 +360,8 @@ class ActivityProcessor(object):
|
|||
if prev_session is None and new_session is None:
|
||||
args = [last_id, last_id]
|
||||
elif prev_progress_percent < media_watched_percent and \
|
||||
prev_session['view_offset'] <= new_session['view_offset']:
|
||||
prev_session['view_offset'] <= new_session['view_offset'] or \
|
||||
session['live'] and prev_session['guid'] == new_session['guid']:
|
||||
args = [prev_session['reference_id'], new_session['id']]
|
||||
else:
|
||||
args = [new_session['id'], new_session['id']]
|
||||
|
@ -458,7 +493,11 @@ class ActivityProcessor(object):
|
|||
'actors': actors,
|
||||
'genres': genres,
|
||||
'studio': metadata['studio'],
|
||||
'labels': labels
|
||||
'labels': labels,
|
||||
'live': session['live'],
|
||||
'channel_call_sign': media_info.get('channel_call_sign', ''),
|
||||
'channel_identifier': media_info.get('channel_identifier', ''),
|
||||
'channel_thumb': media_info.get('channel_thumb', '')
|
||||
}
|
||||
|
||||
# logger.debug("Tautulli ActivityProcessor :: Writing sessionKey %s session_history_metadata transaction..."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue