mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-14 02:26:58 -07:00
Initial implementation of server statistics
This commit is contained in:
parent
8138c27242
commit
3436175223
5 changed files with 348 additions and 11 deletions
|
@ -171,6 +171,38 @@ class PmsConnect(object):
|
|||
|
||||
return request
|
||||
|
||||
"""
|
||||
Return list of libraries on server.
|
||||
|
||||
Optional parameters: output_format { dict, json }
|
||||
|
||||
Output: array
|
||||
"""
|
||||
def get_libraries_list(self, output_format=''):
|
||||
uri = '/library/sections'
|
||||
request = self.request_handler.make_request(uri=uri,
|
||||
proto=self.protocol,
|
||||
request_type='GET',
|
||||
output_format=output_format)
|
||||
|
||||
return request
|
||||
|
||||
"""
|
||||
Return list of items in library on server.
|
||||
|
||||
Optional parameters: output_format { dict, json }
|
||||
|
||||
Output: array
|
||||
"""
|
||||
def get_library_list(self, section_key='', list_type='all', count='0', sort_type='', output_format=''):
|
||||
uri = '/library/sections/' + section_key + '/' + list_type +'?X-Plex-Container-Start=0&X-Plex-Container-Size=' + count + sort_type
|
||||
request = self.request_handler.make_request(uri=uri,
|
||||
proto=self.protocol,
|
||||
request_type='GET',
|
||||
output_format=output_format)
|
||||
|
||||
return request
|
||||
|
||||
"""
|
||||
Return sync item details.
|
||||
|
||||
|
@ -984,6 +1016,151 @@ class PmsConnect(object):
|
|||
logger.debug(u"Server preferences queried but no parameter received.")
|
||||
return None
|
||||
|
||||
"""
|
||||
Return processed and validated server libraries list.
|
||||
|
||||
Output: array
|
||||
"""
|
||||
def get_server_children(self):
|
||||
libraries_data = self.get_libraries_list(output_format='xml')
|
||||
|
||||
try:
|
||||
xml_head = libraries_data.getElementsByTagName('MediaContainer')
|
||||
except:
|
||||
logger.warn("Unable to parse XML for get_libraries_list.")
|
||||
return []
|
||||
|
||||
libraries_list = []
|
||||
|
||||
for a in xml_head:
|
||||
if a.getAttribute('size'):
|
||||
if a.getAttribute('size') == '0':
|
||||
logger.debug(u"No libraries data.")
|
||||
libraries_list = {'libraries_count': '0',
|
||||
'libraries_list': []
|
||||
}
|
||||
return libraries_list
|
||||
|
||||
if a.getElementsByTagName('Directory'):
|
||||
result_data = a.getElementsByTagName('Directory')
|
||||
for result in result_data:
|
||||
libraries_output = {'key': helpers.get_xml_attr(result, 'key'),
|
||||
'type': helpers.get_xml_attr(result, 'type'),
|
||||
'title': helpers.get_xml_attr(result, 'title'),
|
||||
'thumb': helpers.get_xml_attr(result, 'thumb')
|
||||
}
|
||||
libraries_list.append(libraries_output)
|
||||
|
||||
output = {'libraries_count': helpers.get_xml_attr(xml_head[0], 'size'),
|
||||
'title': helpers.get_xml_attr(xml_head[0], 'title1'),
|
||||
'libraries_list': libraries_list
|
||||
}
|
||||
|
||||
return output
|
||||
|
||||
"""
|
||||
Return processed and validated server library items list.
|
||||
|
||||
Parameters required: library_type { movie, show, episode, artist }
|
||||
section_key { unique library key }
|
||||
|
||||
Output: array
|
||||
"""
|
||||
def get_library_children(self, library_type='', section_key='', list_type='all', sort_type = ''):
|
||||
|
||||
# Currently only grab the library with 1 items so 'size' is not 0
|
||||
count = '1'
|
||||
|
||||
if library_type == 'movie':
|
||||
sort_type = '&type=1'
|
||||
elif library_type == 'show':
|
||||
sort_type = '&type=2'
|
||||
elif library_type == 'episode':
|
||||
sort_type = '&type=4'
|
||||
elif library_type == 'album':
|
||||
list_type = 'albums'
|
||||
|
||||
library_data = self.get_library_list(section_key, list_type, count, sort_type, output_format='xml')
|
||||
|
||||
try:
|
||||
xml_head = library_data.getElementsByTagName('MediaContainer')
|
||||
except:
|
||||
logger.warn("Unable to parse XML for get_library_children.")
|
||||
return []
|
||||
|
||||
library_list = []
|
||||
|
||||
for a in xml_head:
|
||||
if a.getAttribute('size'):
|
||||
if a.getAttribute('size') == '0':
|
||||
logger.debug(u"No library data.")
|
||||
library_list = {'library_count': '0',
|
||||
'library_list': []
|
||||
}
|
||||
return library_list
|
||||
|
||||
if a.getElementsByTagName('Directory'):
|
||||
result_data = a.getElementsByTagName('Directory')
|
||||
for result in result_data:
|
||||
library_output = {'key': helpers.get_xml_attr(result, 'key'),
|
||||
'type': helpers.get_xml_attr(result, 'type'),
|
||||
'title': helpers.get_xml_attr(result, 'title'),
|
||||
'thumb': helpers.get_xml_attr(result, 'thumb')
|
||||
}
|
||||
library_list.append(library_output)
|
||||
|
||||
output = {'library_count': helpers.get_xml_attr(xml_head[0], 'totalSize'),
|
||||
'count_type': helpers.get_xml_attr(xml_head[0], 'title2'),
|
||||
'library_list': library_list
|
||||
}
|
||||
|
||||
return output
|
||||
|
||||
"""
|
||||
Return processed and validated server statistics.
|
||||
|
||||
Output: array
|
||||
"""
|
||||
def get_server_stats(self):
|
||||
server_info = self.get_servers_info()
|
||||
server_libraries = self.get_server_children()
|
||||
|
||||
server_stats = []
|
||||
|
||||
if server_libraries['libraries_count'] != '0':
|
||||
libraries_list = server_libraries['libraries_list']
|
||||
|
||||
for library in libraries_list:
|
||||
library_type = library['type']
|
||||
section_key = library['key']
|
||||
library_list = self.get_library_children(library_type, section_key)
|
||||
|
||||
if library_list['library_count'] != '0':
|
||||
library_stats = {'title': library['title'],
|
||||
'thumb': library['thumb'],
|
||||
'count': library_list['library_count'],
|
||||
'count_type': library_list['count_type']
|
||||
}
|
||||
|
||||
if library_type == 'show':
|
||||
episode_list = self.get_library_children(library_type='episode', section_key=section_key)
|
||||
episode_stats = {'episode_count': episode_list['library_count'],
|
||||
'episode_count_type': 'All Episodes'
|
||||
}
|
||||
library_stats.update(episode_stats)
|
||||
|
||||
if library_type == 'artist':
|
||||
album_list = self.get_library_children(library_type='album', section_key=section_key)
|
||||
album_stats = {'album_count': album_list['library_count'],
|
||||
'album_count_type': 'All Albums'
|
||||
}
|
||||
library_stats.update(album_stats)
|
||||
|
||||
server_stats.append({'type': library_type,
|
||||
'rows': library_stats})
|
||||
|
||||
return server_stats
|
||||
|
||||
"""
|
||||
Return image data as array.
|
||||
Array contains the image content type and image binary
|
||||
|
|
|
@ -67,7 +67,8 @@ class WebInterface(object):
|
|||
config = {
|
||||
"home_stats_length": plexpy.CONFIG.HOME_STATS_LENGTH,
|
||||
"home_stats_type": plexpy.CONFIG.HOME_STATS_TYPE,
|
||||
"home_stats_count": plexpy.CONFIG.HOME_STATS_COUNT
|
||||
"home_stats_count": plexpy.CONFIG.HOME_STATS_COUNT,
|
||||
"pms_identifier": plexpy.CONFIG.PMS_IDENTIFIER,
|
||||
}
|
||||
return serve_template(templatename="index.html", title="Home", config=config)
|
||||
|
||||
|
@ -126,6 +127,13 @@ class WebInterface(object):
|
|||
|
||||
return serve_template(templatename="home_stats.html", title="Stats", data=stats_data)
|
||||
|
||||
@cherrypy.expose
|
||||
def server_stats(self, **kwargs):
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
stats_data = pms_connect.get_server_stats()
|
||||
|
||||
return serve_template(templatename="server_stats.html", title="Server Stats", data=stats_data)
|
||||
|
||||
@cherrypy.expose
|
||||
def history(self):
|
||||
return serve_template(templatename="history.html", title="History")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue