mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-12 08:16:06 -07:00
get_libray_media_stats API call
This commit is contained in:
parent
e29cbdf9f9
commit
aed84852c0
3 changed files with 75 additions and 2 deletions
|
@ -143,6 +143,36 @@ def has_library_type(section_type):
|
|||
result = monitor_db.select_single(query=query, args=args)
|
||||
return bool(result)
|
||||
|
||||
def get_library_media_stats(section_id=None):
|
||||
plex = Plex(token=session.get_session_user_token())
|
||||
|
||||
default_return = {
|
||||
'total_size': 0,
|
||||
'total_storage': 0,
|
||||
'total_duration': 0
|
||||
}
|
||||
|
||||
if section_id and not str(section_id).isdigit():
|
||||
logger.warn("Tautulli Libraries :: Library media stats requested but invalid section_id provided.")
|
||||
return default_return
|
||||
|
||||
if not session.allow_session_library(section_id):
|
||||
logger.warn("Tautulli Libraries :: Library media stats requested but library is not allowed for this session.")
|
||||
return default_return
|
||||
|
||||
library = plex.get_library(section_id)
|
||||
|
||||
if library is None:
|
||||
logger.warn("Tautulli Libraries :: Library media stats requested but no library was found section_id %s.", section_id)
|
||||
return default_return
|
||||
|
||||
library_media_stats = {
|
||||
'total_size': library.totalSize,
|
||||
'total_storage': library.totalStorage,
|
||||
'total_duration': library.totalDuration
|
||||
}
|
||||
|
||||
return library_media_stats
|
||||
|
||||
def get_collections(section_id=None):
|
||||
plex = Plex(token=session.get_session_user_token())
|
||||
|
@ -409,18 +439,23 @@ class Libraries(object):
|
|||
else:
|
||||
library_art = item['library_art']
|
||||
|
||||
library_media_stats = get_library_media_stats(item['section_id'])
|
||||
|
||||
row = {'row_id': item['row_id'],
|
||||
'server_id': item['server_id'],
|
||||
'section_id': item['section_id'],
|
||||
'section_name': item['section_name'],
|
||||
'section_type': item['section_type'],
|
||||
'count': item['count'],
|
||||
'total_size': library_media_stats['total_size'],
|
||||
'parent_count': item['parent_count'],
|
||||
'child_count': item['child_count'],
|
||||
'library_thumb': library_thumb,
|
||||
'library_art': library_art,
|
||||
'plays': item['plays'],
|
||||
'total_storage': library_media_stats['total_storage'],
|
||||
'duration': item['duration'],
|
||||
'total_duration': library_media_stats['total_duration'],
|
||||
'last_accessed': item['last_accessed'],
|
||||
'history_row_id': item['history_row_id'],
|
||||
'last_played': item['last_played'],
|
||||
|
|
|
@ -59,7 +59,14 @@ class Plex(object):
|
|||
self.PlexServer = PlexObject(url, token)
|
||||
|
||||
def get_library(self, section_id):
|
||||
return self.PlexServer.library.sectionByID(int(section_id))
|
||||
from plexapi.exceptions import NotFound
|
||||
|
||||
try:
|
||||
library = self.PlexServer.library.sectionByID(int(section_id))
|
||||
except NotFound:
|
||||
library = None
|
||||
|
||||
return library
|
||||
|
||||
def get_library_items(self, section_id):
|
||||
return self.get_library(section_id).all()
|
||||
|
|
|
@ -540,6 +540,9 @@ class WebInterface(object):
|
|||
"section_type": "Show",
|
||||
"server_id": "ds48g4r354a8v9byrrtr697g3g79w",
|
||||
"thumb": "/library/metadata/153036/thumb/1462175062",
|
||||
"total_duration": 3048551210,
|
||||
"total_size": 62,
|
||||
"total_storage": 1866078986762,
|
||||
"year": 2016
|
||||
},
|
||||
{...},
|
||||
|
@ -561,7 +564,9 @@ class WebInterface(object):
|
|||
("last_accessed", True, False),
|
||||
("last_played", True, True),
|
||||
("plays", True, False),
|
||||
("duration", True, False)]
|
||||
("duration", True, False),
|
||||
("total_storage", True, False),
|
||||
("total_duration", True, False)]
|
||||
kwargs['json_data'] = build_datatables_json(kwargs, dt_columns, "section_name")
|
||||
|
||||
grouping = helpers.bool_true(grouping, return_none=True)
|
||||
|
@ -695,6 +700,32 @@ class WebInterface(object):
|
|||
except:
|
||||
return "Failed to update library."
|
||||
|
||||
@cherrypy.expose
|
||||
@requireAuth(member_of("admin"))
|
||||
@addtoapi()
|
||||
def get_library_media_stats(self, section_id=None):
|
||||
""" Get the media stats of a library section on Tautulli.
|
||||
|
||||
```
|
||||
Required parameters:
|
||||
section_id (str): The id of the Plex library section
|
||||
|
||||
Optional parameters:
|
||||
None
|
||||
|
||||
Returns:
|
||||
{
|
||||
"total_duration": 3048551210,
|
||||
"total_size": 62,
|
||||
"total_storage": 1866078986762
|
||||
}
|
||||
```
|
||||
"""
|
||||
|
||||
logger.info("Getting library media stats for section %s.", section_id)
|
||||
|
||||
return libraries.get_library_media_stats(section_id)
|
||||
|
||||
@cherrypy.expose
|
||||
@requireAuth()
|
||||
def library_watch_time_stats(self, section_id=None, **kwargs):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue