diff --git a/data/interfaces/default/home_stats.html b/data/interfaces/default/home_stats.html index 4098cf3b..e24c26ed 100644 --- a/data/interfaces/default/home_stats.html +++ b/data/interfaces/default/home_stats.html @@ -80,7 +80,7 @@ DOCUMENTATION :: END <% fallback = 'art-live' if row0['live'] else row0['library_art'] %>
% elif stat_id == 'top_users': -
+
% elif stat_id == 'top_platforms':
% else: @@ -118,7 +118,7 @@ DOCUMENTATION :: END % elif stat_id == 'top_users': <% user_href = page('user', row0['user_id']) if row0['user_id'] else '#' %> % elif stat_id == 'top_platforms': diff --git a/data/interfaces/default/library_stats.html b/data/interfaces/default/library_stats.html index 92849bef..412c7c8e 100644 --- a/data/interfaces/default/library_stats.html +++ b/data/interfaces/default/library_stats.html @@ -60,8 +60,8 @@ DOCUMENTATION :: END data-art="${section.get('art')}" data-thumb="${section.get('thumb')}" data-library_art="${section.get('library_art')}">
${loop.index + 1}
% if headers[section_type][1][0]: diff --git a/plexpy/__init__.py b/plexpy/__init__.py index 7d745678..b6e763ed 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -731,8 +731,7 @@ def dbcheck(): "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, " "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, " - "server_id TEXT)" + "filter_all TEXT, filter_movies TEXT, filter_tv TEXT, filter_music TEXT, filter_photos TEXT)" ) # library_sections table :: This table keeps record of the servers library sections diff --git a/plexpy/activity_processor.py b/plexpy/activity_processor.py index a4f50485..1d5394b3 100644 --- a/plexpy/activity_processor.py +++ b/plexpy/activity_processor.py @@ -417,7 +417,7 @@ class ActivityProcessor(object): 'optimized_version': session['optimized_version'], 'optimized_version_profile': session['optimized_version_profile'], '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..." diff --git a/plexpy/datafactory.py b/plexpy/datafactory.py index 82803631..af98be46 100644 --- a/plexpy/datafactory.py +++ b/plexpy/datafactory.py @@ -392,7 +392,7 @@ class DataFactory(object): if stat == 'top_movies': top_movies = [] 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, " \ "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) - " \ @@ -432,7 +432,8 @@ class DataFactory(object): 'platform': '', 'live': item['live'], 'guid': item['guid'], - 'row_id': item['id'] + 'row_id': item['id'], + 'server_id': item['server_id'] } top_movies.append(row) @@ -444,7 +445,7 @@ class DataFactory(object): elif stat == 'popular_movies': popular_movies = [] 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, " \ "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 " \ @@ -484,7 +485,8 @@ class DataFactory(object): 'platform': '', 'live': item['live'], 'guid': item['guid'], - 'row_id': item['id'] + 'row_id': item['id'], + 'server_id': item['server_id'] } popular_movies.append(row) @@ -495,7 +497,7 @@ class DataFactory(object): elif stat == 'top_tv': top_tv = [] 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.year, sh.rating_key, shm.art, sh.media_type, " \ "shm.content_rating, shm.labels, sh.started, shm.live, shm.guid, " \ @@ -537,7 +539,8 @@ class DataFactory(object): 'platform': '', 'live': item['live'], 'guid': item['guid'], - 'row_id': item['id'] + 'row_id': item['id'], + 'server_id': item['server_id'] } top_tv.append(row) @@ -549,7 +552,7 @@ class DataFactory(object): elif stat == 'popular_tv': popular_tv = [] 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.year, sh.rating_key, shm.art, sh.media_type, " \ "shm.content_rating, shm.labels, sh.started, shm.live, shm.guid, " \ @@ -591,7 +594,8 @@ class DataFactory(object): 'platform': '', 'live': item['live'], 'guid': item['guid'], - 'row_id': item['id'] + 'row_id': item['id'], + 'server_id': item['server_id'] } popular_tv.append(row) @@ -602,7 +606,7 @@ class DataFactory(object): elif stat == 'top_music': top_music = [] 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, " \ "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 " \ @@ -643,7 +647,8 @@ class DataFactory(object): 'platform': '', 'live': item['live'], 'guid': item['guid'], - 'row_id': item['id'] + 'row_id': item['id'], + 'server_id': item['server_id'] } top_music.append(row) @@ -655,7 +660,7 @@ class DataFactory(object): elif stat == 'popular_music': popular_music = [] 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, " \ "shm.art, sh.media_type, shm.content_rating, shm.labels, sh.started, shm.live, shm.guid, " \ "COUNT(DISTINCT sh.user_id) AS users_watched, " \ @@ -696,7 +701,8 @@ class DataFactory(object): 'platform': '', 'live': item['live'], 'guid': item['guid'], - 'row_id': item['id'] + 'row_id': item['id'], + 'server_id': item['server_id'] } popular_music.append(row) @@ -707,7 +713,7 @@ class DataFactory(object): elif stat == 'top_libraries': top_libraries = [] 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, " \ "sh.rating_key, shm.grandparent_rating_key, shm.thumb, shm.grandparent_thumb, " \ "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 (), 'live': item['live'], 'guid': item['guid'], - 'row_id': item['id'] + 'row_id': item['id'], + 'server_id': item['server_id'] } top_libraries.append(row) @@ -957,7 +964,7 @@ class DataFactory(object): last_watched = [] 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, " \ "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, " \ @@ -1019,7 +1026,8 @@ class DataFactory(object): 'last_watch': item['last_watch'], 'live': item['live'], 'guid': item['guid'], - 'player': item['player'] + 'player': item['player'], + 'server_id': item['server_id'] } last_watched.append(row) @@ -1173,6 +1181,9 @@ class DataFactory(object): else: 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'], 'section_name': item['section_name'], 'section_type': item['section_type'], @@ -1198,7 +1209,8 @@ class DataFactory(object): 'live': item['live'], 'guid': item['guid'], 'row_id': item['id'], - 'server_id': item['server_id'] + 'server_id': item['server_id'], + 'server_name': server_info['name'] } library_stats.append(library) @@ -1303,7 +1315,7 @@ class DataFactory(object): 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: grouping = plexpy.CONFIG.GROUP_HISTORY_TABLES @@ -1335,12 +1347,12 @@ class DataFactory(object): "FROM session_history " \ "JOIN session_history_metadata ON session_history_metadata.id = session_history.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.rating_key IN (%s)) " \ "GROUP BY users.user_id " \ "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) diff --git a/plexpy/libraries.py b/plexpy/libraries.py index 4172089f..e77b750a 100644 --- a/plexpy/libraries.py +++ b/plexpy/libraries.py @@ -1082,7 +1082,7 @@ class Libraries(object): 'user': row['user'], 'section_id': row['section_id'], 'content_rating': row['content_rating'], - 'server_id': row['server_id'], + 'server_id': server_id, 'labels': row['labels'].split(';') if row['labels'] else (), } recently_watched.append(recent_output) diff --git a/plexpy/users.py b/plexpy/users.py index 0e201791..66cc9ebb 100644 --- a/plexpy/users.py +++ b/plexpy/users.py @@ -630,7 +630,7 @@ class Users(object): try: 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, " \ "title, parent_title, grandparent_title, original_title, " \ "thumb, parent_thumb, grandparent_thumb, media_index, parent_media_index, " \ @@ -673,7 +673,8 @@ class Users(object): 'live': row['live'], 'guid': row['guid'], 'time': row['started'], - 'user': row['user'] + 'user': row['user'], + 'server_id': row['server_id'] } recently_watched.append(recent_output) diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 82afcec5..a115f73d 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -759,7 +759,7 @@ class WebInterface(object): if not allow_session_library(section_id): 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() result = library_data.get_recently_watched(section_id=section_id, limit=limit, server_id=server_id) else: @@ -4426,7 +4426,7 @@ class WebInterface(object): user_info = {} # 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) metadata = pms_connect.get_metadata_details(rating_key=rating_key, section_id=section_id) metadata['server_id'] = pms_connect.get_server_info()['machine_identifier'] @@ -4500,10 +4500,10 @@ class WebInterface(object): @cherrypy.expose @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: 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: result = None @@ -5182,17 +5182,18 @@ class WebInterface(object): @cherrypy.expose @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 = [] - for pms_connect in server_manager.ServerManger().get_server_list(): - result += pms_connect.get_search_results(query=query, limit=limit) + result ={} + pms_connect = server_manager.ServerManger().get_server(server_id=server_id) + if pms_connect: + result = pms_connect.get_search_results(query=query, limit=limit) - if media_type: - result['results_list'] = {media_type: result['results_list'][media_type]} - if media_type == 'season' and season_index: - result['results_list']['season'] = [season for season in result['results_list']['season'] - if season['media_index'] == season_index] + if media_type: + result['results_list'] = {media_type: result['results_list'][media_type]} + if media_type == 'season' and season_index: + result['results_list']['season'] = [season for season in result['results_list']['season'] + if season['media_index'] == season_index] if result: return serve_template(template_name="info_search_results_list.html", data=result, title="Search Result List")