mostly working stats pages

watch history updates
This commit is contained in:
tyler breese 2023-10-17 00:17:43 -04:00
commit 67d95d4670
8 changed files with 56 additions and 43 deletions

View file

@ -80,7 +80,7 @@ DOCUMENTATION :: END
<% fallback = 'art-live' if row0['live'] else row0['library_art'] %> <% fallback = 'art-live' if row0['live'] else row0['library_art'] %>
<div id="stats-background-${stat_id}" class="dashboard-stats-background" style="background-image: url(${page('pms_image_proxy', row0['art'] or row0['library_art'], None, 500, 280, 40, '282828', 3, fallback=fallback, server_id=row0['server_id'])});" data-library_art="${row0['library_art']}"> <div id="stats-background-${stat_id}" class="dashboard-stats-background" style="background-image: url(${page('pms_image_proxy', row0['art'] or row0['library_art'], None, 500, 280, 40, '282828', 3, fallback=fallback, server_id=row0['server_id'])});" data-library_art="${row0['library_art']}">
% elif stat_id == 'top_users': % elif stat_id == 'top_users':
<div id="stats-background-${stat_id}" class="dashboard-stats-background" data-blurhash="${page('pms_image_proxy', row0['user_thumb'] or 'interfaces/default/images/gravatar-default.png', None, 100, 100, 40, '282828', 0, fallback='user', server_id=row0['server_id'])}"> <div id="stats-background-${stat_id}" class="dashboard-stats-background" data-blurhash="${page('pms_image_proxy', row0['user_thumb'] or 'interfaces/default/images/gravatar-default.png', None, 100, 100, 40, '282828', 0, fallback='user')}">
% elif stat_id == 'top_platforms': % elif stat_id == 'top_platforms':
<div id="stats-background-${stat_id}" class="dashboard-stats-background platform-${row0['platform_name']}-rgba no-image"> <div id="stats-background-${stat_id}" class="dashboard-stats-background platform-${row0['platform_name']}-rgba no-image">
% else: % else:
@ -118,7 +118,7 @@ DOCUMENTATION :: END
% elif stat_id == 'top_users': % elif stat_id == 'top_users':
<% user_href = page('user', row0['user_id']) if row0['user_id'] else '#' %> <% user_href = page('user', row0['user_id']) if row0['user_id'] else '#' %>
<a id="stats-thumb-url-${stat_id}" href="${user_href}" title="${row0['user']}" class="hidden-xs"> <a id="stats-thumb-url-${stat_id}" href="${user_href}" title="${row0['user']}" class="hidden-xs">
<div id="stats-thumb-${stat_id}" class="dashboard-stats-circle" style="background-image: url(${page('pms_image_proxy', row0['user_thumb'] or 'interfaces/default/images/gravatar-default.png', None, 100, 100, fallback='user', server_id=row0['server_id'])})"></div> <div id="stats-thumb-${stat_id}" class="dashboard-stats-circle" style="background-image: url(${page('pms_image_proxy', row0['user_thumb'] or 'interfaces/default/images/gravatar-default.png', None, 100, 100, fallback='user')})"></div>
</a> </a>
% elif stat_id == 'top_platforms': % elif stat_id == 'top_platforms':
<div id="stats-thumb-${stat_id}" class="dashboard-stats-flat svg-icon platform-${row0['platform_name']} transparent hidden-xs"></div> <div id="stats-thumb-${stat_id}" class="dashboard-stats-flat svg-icon platform-${row0['platform_name']} transparent hidden-xs"></div>

View file

@ -60,8 +60,8 @@ DOCUMENTATION :: END
data-art="${section.get('art')}" data-thumb="${section.get('thumb')}" data-library_art="${section.get('library_art')}"> data-art="${section.get('art')}" data-thumb="${section.get('thumb')}" data-library_art="${section.get('library_art')}">
<div class="sub-list">${loop.index + 1}</div> <div class="sub-list">${loop.index + 1}</div>
<div class="sub-value"> <div class="sub-value">
<a href="${page('library', section['section_id'], server_id=section['server_id'])}" title="${section['section_name']}"> <a href="${page('library', section['section_id'], server_id=section['server_id'])}" title="${section['section_name']} (${section['server_name']})">
${section['section_name']} ${section['section_name']} (${section['server_name']})
</a> </a>
</div> </div>
% if headers[section_type][1][0]: % if headers[section_type][1][0]:

View file

@ -731,8 +731,7 @@ def dbcheck():
"is_allow_sync INTEGER DEFAULT NULL, is_restricted INTEGER DEFAULT NULL, " "is_allow_sync INTEGER DEFAULT NULL, is_restricted INTEGER DEFAULT NULL, "
"do_notify INTEGER DEFAULT 1, keep_history INTEGER DEFAULT 1, deleted_user INTEGER DEFAULT 0, " "do_notify INTEGER DEFAULT 1, keep_history INTEGER DEFAULT 1, deleted_user INTEGER DEFAULT 0, "
"allow_guest INTEGER DEFAULT 0, user_token TEXT, server_token TEXT, shared_libraries TEXT, " "allow_guest INTEGER DEFAULT 0, user_token TEXT, server_token TEXT, shared_libraries TEXT, "
"filter_all TEXT, filter_movies TEXT, filter_tv TEXT, filter_music TEXT, filter_photos TEXT, " "filter_all TEXT, filter_movies TEXT, filter_tv TEXT, filter_music TEXT, filter_photos TEXT)"
"server_id TEXT)"
) )
# library_sections table :: This table keeps record of the servers library sections # library_sections table :: This table keeps record of the servers library sections

View file

@ -417,7 +417,7 @@ class ActivityProcessor(object):
'optimized_version': session['optimized_version'], 'optimized_version': session['optimized_version'],
'optimized_version_profile': session['optimized_version_profile'], 'optimized_version_profile': session['optimized_version_profile'],
'optimized_version_title': session['optimized_version_title'], 'optimized_version_title': session['optimized_version_title'],
'server_id': "test3" 'server_id': session['server_id']
} }
# logger.debug("Tautulli ActivityProcessor :: Writing sessionKey %s session_history_media_info transaction..." # logger.debug("Tautulli ActivityProcessor :: Writing sessionKey %s session_history_media_info transaction..."

View file

@ -392,7 +392,7 @@ class DataFactory(object):
if stat == 'top_movies': if stat == 'top_movies':
top_movies = [] top_movies = []
try: try:
query = "SELECT sh.id, shm.full_title, shm.year, sh.rating_key, shm.thumb, sh.section_id, " \ query = "SELECT sh.id, sh.server_id, shm.full_title, shm.year, sh.rating_key, shm.thumb, sh.section_id, " \
"shm.art, sh.media_type, shm.content_rating, shm.labels, sh.started, shm.live, shm.guid, " \ "shm.art, sh.media_type, shm.content_rating, shm.labels, sh.started, shm.live, shm.guid, " \
"MAX(sh.started) AS last_watch, COUNT(sh.id) AS total_plays, SUM(sh.d) AS total_duration " \ "MAX(sh.started) AS last_watch, COUNT(sh.id) AS total_plays, SUM(sh.d) AS total_duration " \
"FROM (SELECT *, SUM(CASE WHEN stopped > 0 THEN (stopped - started) - " \ "FROM (SELECT *, SUM(CASE WHEN stopped > 0 THEN (stopped - started) - " \
@ -432,7 +432,8 @@ class DataFactory(object):
'platform': '', 'platform': '',
'live': item['live'], 'live': item['live'],
'guid': item['guid'], 'guid': item['guid'],
'row_id': item['id'] 'row_id': item['id'],
'server_id': item['server_id']
} }
top_movies.append(row) top_movies.append(row)
@ -444,7 +445,7 @@ class DataFactory(object):
elif stat == 'popular_movies': elif stat == 'popular_movies':
popular_movies = [] popular_movies = []
try: try:
query = "SELECT sh.id, shm.full_title, shm.year, sh.rating_key, shm.thumb, sh.section_id, " \ query = "SELECT sh.id, sh.server_id, shm.full_title, shm.year, sh.rating_key, shm.thumb, sh.section_id, " \
"shm.art, sh.media_type, shm.content_rating, shm.labels, sh.started, shm.live, shm.guid, " \ "shm.art, sh.media_type, shm.content_rating, shm.labels, sh.started, shm.live, shm.guid, " \
"COUNT(DISTINCT sh.user_id) AS users_watched, " \ "COUNT(DISTINCT sh.user_id) AS users_watched, " \
"MAX(sh.started) AS last_watch, COUNT(sh.id) as total_plays, SUM(sh.d) AS total_duration " \ "MAX(sh.started) AS last_watch, COUNT(sh.id) as total_plays, SUM(sh.d) AS total_duration " \
@ -484,7 +485,8 @@ class DataFactory(object):
'platform': '', 'platform': '',
'live': item['live'], 'live': item['live'],
'guid': item['guid'], 'guid': item['guid'],
'row_id': item['id'] 'row_id': item['id'],
'server_id': item['server_id']
} }
popular_movies.append(row) popular_movies.append(row)
@ -495,7 +497,7 @@ class DataFactory(object):
elif stat == 'top_tv': elif stat == 'top_tv':
top_tv = [] top_tv = []
try: try:
query = "SELECT sh.id, shm.grandparent_title, sh.grandparent_rating_key, " \ query = "SELECT sh.id, sh.server_id, shm.grandparent_title, sh.grandparent_rating_key, " \
"shm.grandparent_thumb, sh.section_id, " \ "shm.grandparent_thumb, sh.section_id, " \
"shm.year, sh.rating_key, shm.art, sh.media_type, " \ "shm.year, sh.rating_key, shm.art, sh.media_type, " \
"shm.content_rating, shm.labels, sh.started, shm.live, shm.guid, " \ "shm.content_rating, shm.labels, sh.started, shm.live, shm.guid, " \
@ -537,7 +539,8 @@ class DataFactory(object):
'platform': '', 'platform': '',
'live': item['live'], 'live': item['live'],
'guid': item['guid'], 'guid': item['guid'],
'row_id': item['id'] 'row_id': item['id'],
'server_id': item['server_id']
} }
top_tv.append(row) top_tv.append(row)
@ -549,7 +552,7 @@ class DataFactory(object):
elif stat == 'popular_tv': elif stat == 'popular_tv':
popular_tv = [] popular_tv = []
try: try:
query = "SELECT sh.id, shm.grandparent_title, sh.grandparent_rating_key, " \ query = "SELECT sh.id, sh.server_id, shm.grandparent_title, sh.grandparent_rating_key, " \
"shm.grandparent_thumb, sh.section_id, " \ "shm.grandparent_thumb, sh.section_id, " \
"shm.year, sh.rating_key, shm.art, sh.media_type, " \ "shm.year, sh.rating_key, shm.art, sh.media_type, " \
"shm.content_rating, shm.labels, sh.started, shm.live, shm.guid, " \ "shm.content_rating, shm.labels, sh.started, shm.live, shm.guid, " \
@ -591,7 +594,8 @@ class DataFactory(object):
'platform': '', 'platform': '',
'live': item['live'], 'live': item['live'],
'guid': item['guid'], 'guid': item['guid'],
'row_id': item['id'] 'row_id': item['id'],
'server_id': item['server_id']
} }
popular_tv.append(row) popular_tv.append(row)
@ -602,7 +606,7 @@ class DataFactory(object):
elif stat == 'top_music': elif stat == 'top_music':
top_music = [] top_music = []
try: try:
query = "SELECT sh.id, shm.grandparent_title, shm.original_title, shm.year, " \ query = "SELECT sh.id, sh.server_id, shm.grandparent_title, shm.original_title, shm.year, " \
"sh.grandparent_rating_key, shm.grandparent_thumb, sh.section_id, " \ "sh.grandparent_rating_key, shm.grandparent_thumb, sh.section_id, " \
"shm.art, sh.media_type, shm.content_rating, shm.labels, sh.started, shm.live, shm.guid, " \ "shm.art, sh.media_type, shm.content_rating, shm.labels, sh.started, shm.live, shm.guid, " \
"MAX(sh.started) AS last_watch, COUNT(sh.id) AS total_plays, SUM(sh.d) AS total_duration " \ "MAX(sh.started) AS last_watch, COUNT(sh.id) AS total_plays, SUM(sh.d) AS total_duration " \
@ -643,7 +647,8 @@ class DataFactory(object):
'platform': '', 'platform': '',
'live': item['live'], 'live': item['live'],
'guid': item['guid'], 'guid': item['guid'],
'row_id': item['id'] 'row_id': item['id'],
'server_id': item['server_id']
} }
top_music.append(row) top_music.append(row)
@ -655,7 +660,7 @@ class DataFactory(object):
elif stat == 'popular_music': elif stat == 'popular_music':
popular_music = [] popular_music = []
try: try:
query = "SELECT sh.id, shm.grandparent_title, shm.original_title, shm.year, " \ query = "SELECT sh.id, sh.server_id, shm.grandparent_title, shm.original_title, shm.year, " \
"sh.grandparent_rating_key, shm.grandparent_thumb, sh.section_id, " \ "sh.grandparent_rating_key, shm.grandparent_thumb, sh.section_id, " \
"shm.art, sh.media_type, shm.content_rating, shm.labels, sh.started, shm.live, shm.guid, " \ "shm.art, sh.media_type, shm.content_rating, shm.labels, sh.started, shm.live, shm.guid, " \
"COUNT(DISTINCT sh.user_id) AS users_watched, " \ "COUNT(DISTINCT sh.user_id) AS users_watched, " \
@ -696,7 +701,8 @@ class DataFactory(object):
'platform': '', 'platform': '',
'live': item['live'], 'live': item['live'],
'guid': item['guid'], 'guid': item['guid'],
'row_id': item['id'] 'row_id': item['id'],
'server_id': item['server_id']
} }
popular_music.append(row) popular_music.append(row)
@ -707,7 +713,7 @@ class DataFactory(object):
elif stat == 'top_libraries': elif stat == 'top_libraries':
top_libraries = [] top_libraries = []
try: try:
query = "SELECT sh.id, shm.title, shm.grandparent_title, shm.full_title, shm.year, " \ query = "SELECT sh.id, sh.server_id, shm.title, shm.grandparent_title, shm.full_title, shm.year, " \
"shm.media_index, shm.parent_media_index, " \ "shm.media_index, shm.parent_media_index, " \
"sh.rating_key, shm.grandparent_rating_key, shm.thumb, shm.grandparent_thumb, " \ "sh.rating_key, shm.grandparent_rating_key, shm.thumb, shm.grandparent_thumb, " \
"sh.user, sh.user_id, sh.player, sh.section_id, " \ "sh.user, sh.user_id, sh.player, sh.section_id, " \
@ -783,7 +789,8 @@ class DataFactory(object):
'labels': item['labels'].split(';') if item['labels'] else (), 'labels': item['labels'].split(';') if item['labels'] else (),
'live': item['live'], 'live': item['live'],
'guid': item['guid'], 'guid': item['guid'],
'row_id': item['id'] 'row_id': item['id'],
'server_id': item['server_id']
} }
top_libraries.append(row) top_libraries.append(row)
@ -957,7 +964,7 @@ class DataFactory(object):
last_watched = [] last_watched = []
try: try:
query = "SELECT sh.id, shm.title, shm.grandparent_title, shm.full_title, shm.year, " \ query = "SELECT sh.id, sh.server_id, shm.title, shm.grandparent_title, shm.full_title, shm.year, " \
"shm.media_index, shm.parent_media_index, " \ "shm.media_index, shm.parent_media_index, " \
"sh.rating_key, shm.grandparent_rating_key, shm.thumb, shm.grandparent_thumb, " \ "sh.rating_key, shm.grandparent_rating_key, shm.thumb, shm.grandparent_thumb, " \
"sh.user, sh.user_id, u.custom_avatar_url as user_thumb, sh.player, sh.section_id, " \ "sh.user, sh.user_id, u.custom_avatar_url as user_thumb, sh.player, sh.section_id, " \
@ -1019,7 +1026,8 @@ class DataFactory(object):
'last_watch': item['last_watch'], 'last_watch': item['last_watch'],
'live': item['live'], 'live': item['live'],
'guid': item['guid'], 'guid': item['guid'],
'player': item['player'] 'player': item['player'],
'server_id': item['server_id']
} }
last_watched.append(row) last_watched.append(row)
@ -1173,6 +1181,9 @@ class DataFactory(object):
else: else:
thumb = item['grandparent_thumb'] thumb = item['grandparent_thumb']
pmsconnect = server_manager.ServerManger().get_server(item['server_id'])
server_info = pmsconnect.get_server_info()
library = {'section_id': item['section_id'], library = {'section_id': item['section_id'],
'section_name': item['section_name'], 'section_name': item['section_name'],
'section_type': item['section_type'], 'section_type': item['section_type'],
@ -1198,7 +1209,8 @@ class DataFactory(object):
'live': item['live'], 'live': item['live'],
'guid': item['guid'], 'guid': item['guid'],
'row_id': item['id'], 'row_id': item['id'],
'server_id': item['server_id'] 'server_id': item['server_id'],
'server_name': server_info['name']
} }
library_stats.append(library) library_stats.append(library)
@ -1303,7 +1315,7 @@ class DataFactory(object):
return item_watch_time_stats return item_watch_time_stats
def get_user_stats(self, rating_key=None, media_type=None, grouping=None): def get_user_stats(self, rating_key=None, media_type=None, grouping=None, server_id=None):
if grouping is None: if grouping is None:
grouping = plexpy.CONFIG.GROUP_HISTORY_TABLES grouping = plexpy.CONFIG.GROUP_HISTORY_TABLES
@ -1335,12 +1347,12 @@ class DataFactory(object):
"FROM session_history " \ "FROM session_history " \
"JOIN session_history_metadata ON session_history_metadata.id = session_history.id " \ "JOIN session_history_metadata ON session_history_metadata.id = session_history.id " \
"JOIN users ON users.user_id = session_history.user_id " \ "JOIN users ON users.user_id = session_history.user_id " \
"WHERE (session_history.grandparent_rating_key IN (%s) " \ "WHERE session_history.server_id = '%s' AND (session_history.grandparent_rating_key IN (%s) " \
"OR session_history.parent_rating_key IN (%s) " \ "OR session_history.parent_rating_key IN (%s) " \
"OR session_history.rating_key IN (%s)) " \ "OR session_history.rating_key IN (%s)) " \
"GROUP BY users.user_id " \ "GROUP BY users.user_id " \
"ORDER BY total_plays DESC, total_time DESC" % ( "ORDER BY total_plays DESC, total_time DESC" % (
group_by, rating_keys_arg, rating_keys_arg, rating_keys_arg group_by, server_id, rating_keys_arg, rating_keys_arg, rating_keys_arg
) )
result = monitor_db.select(query, args=rating_keys * 3) result = monitor_db.select(query, args=rating_keys * 3)

View file

@ -1082,7 +1082,7 @@ class Libraries(object):
'user': row['user'], 'user': row['user'],
'section_id': row['section_id'], 'section_id': row['section_id'],
'content_rating': row['content_rating'], 'content_rating': row['content_rating'],
'server_id': row['server_id'], 'server_id': server_id,
'labels': row['labels'].split(';') if row['labels'] else (), 'labels': row['labels'].split(';') if row['labels'] else (),
} }
recently_watched.append(recent_output) recently_watched.append(recent_output)

View file

@ -630,7 +630,7 @@ class Users(object):
try: try:
if str(user_id).isdigit(): if str(user_id).isdigit():
query = "SELECT session_history.id, session_history.media_type, guid, " \ query = "SELECT session_history.id, session_history.server_id, session_history.media_type, guid, " \
"session_history.rating_key, session_history.parent_rating_key, session_history.grandparent_rating_key, " \ "session_history.rating_key, session_history.parent_rating_key, session_history.grandparent_rating_key, " \
"title, parent_title, grandparent_title, original_title, " \ "title, parent_title, grandparent_title, original_title, " \
"thumb, parent_thumb, grandparent_thumb, media_index, parent_media_index, " \ "thumb, parent_thumb, grandparent_thumb, media_index, parent_media_index, " \
@ -673,7 +673,8 @@ class Users(object):
'live': row['live'], 'live': row['live'],
'guid': row['guid'], 'guid': row['guid'],
'time': row['started'], 'time': row['started'],
'user': row['user'] 'user': row['user'],
'server_id': row['server_id']
} }
recently_watched.append(recent_output) recently_watched.append(recent_output)

View file

@ -759,7 +759,7 @@ class WebInterface(object):
if not allow_session_library(section_id): if not allow_session_library(section_id):
return serve_template(template_name="user_recently_watched.html", data=None, title="Recently Watched") return serve_template(template_name="user_recently_watched.html", data=None, title="Recently Watched")
if section_id: if section_id and server_id:
library_data = libraries.Libraries() library_data = libraries.Libraries()
result = library_data.get_recently_watched(section_id=section_id, limit=limit, server_id=server_id) result = library_data.get_recently_watched(section_id=section_id, limit=limit, server_id=server_id)
else: else:
@ -4426,7 +4426,7 @@ class WebInterface(object):
user_info = {} user_info = {}
# Try to get metadata from the Plex server first # Try to get metadata from the Plex server first
if rating_key: if rating_key and server_id:
pms_connect = server_manager.ServerManger().get_server(server_id=server_id) pms_connect = server_manager.ServerManger().get_server(server_id=server_id)
metadata = pms_connect.get_metadata_details(rating_key=rating_key, section_id=section_id) metadata = pms_connect.get_metadata_details(rating_key=rating_key, section_id=section_id)
metadata['server_id'] = pms_connect.get_server_info()['machine_identifier'] metadata['server_id'] = pms_connect.get_server_info()['machine_identifier']
@ -4500,10 +4500,10 @@ class WebInterface(object):
@cherrypy.expose @cherrypy.expose
@requireAuth() @requireAuth()
def item_user_stats(self, rating_key=None, media_type=None, **kwargs): def item_user_stats(self, rating_key=None, media_type=None, server_id=None, **kwargs):
if rating_key: if rating_key:
item_data = datafactory.DataFactory() item_data = datafactory.DataFactory()
result = item_data.get_user_stats(rating_key=rating_key, media_type=media_type) result = item_data.get_user_stats(rating_key=rating_key, media_type=media_type, server_id=server_id)
else: else:
result = None result = None
@ -5182,17 +5182,18 @@ class WebInterface(object):
@cherrypy.expose @cherrypy.expose
@requireAuth() @requireAuth()
def get_search_results_children(self, query='', limit='', media_type=None, season_index=None, **kwargs): def get_search_results_children(self, query='', limit='', media_type=None, season_index=None, server_id=None, **kwargs):
result = [] result ={}
for pms_connect in server_manager.ServerManger().get_server_list(): pms_connect = server_manager.ServerManger().get_server(server_id=server_id)
result += pms_connect.get_search_results(query=query, limit=limit) if pms_connect:
result = pms_connect.get_search_results(query=query, limit=limit)
if media_type: if media_type:
result['results_list'] = {media_type: result['results_list'][media_type]} result['results_list'] = {media_type: result['results_list'][media_type]}
if media_type == 'season' and season_index: if media_type == 'season' and season_index:
result['results_list']['season'] = [season for season in result['results_list']['season'] result['results_list']['season'] = [season for season in result['results_list']['season']
if season['media_index'] == season_index] if season['media_index'] == season_index]
if result: if result:
return serve_template(template_name="info_search_results_list.html", data=result, title="Search Result List") return serve_template(template_name="info_search_results_list.html", data=result, title="Search Result List")