diff --git a/data/interfaces/default/library.html b/data/interfaces/default/library.html index 94064523..5a0cf90a 100644 --- a/data/interfaces/default/library.html +++ b/data/interfaces/default/library.html @@ -862,16 +862,20 @@ DOCUMENTATION :: END } $(document).ready(function () { + loadLibraryMediaStats(); + }); + + function loadLibraryMediaStats(refresh) { // Populate media stats $.ajax({ url: 'get_library_media_stats', - data: { section_id: section_id }, + data: { section_id: section_id, refresh: refresh }, complete: function(xhr, status) { $("#info-element-total-runtime").html(humanDuration(xhr.responseJSON.total_duration)); $("#info-element-total-storage").html(humanFileSize(xhr.responseJSON.total_storage)); } }); - }); + } $('#nav-tabs-mediainfo').on('shown.bs.tab', function() { if (typeof(media_info_table) === 'undefined') { @@ -884,6 +888,7 @@ DOCUMENTATION :: END refresh_table = true; refresh_child_tables = true; media_info_table.draw(); + loadLibraryMediaStats(true); refresh_table = false; }); diff --git a/plexpy/libraries.py b/plexpy/libraries.py index 89e21898..b03568a5 100644 --- a/plexpy/libraries.py +++ b/plexpy/libraries.py @@ -143,7 +143,7 @@ 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): +def get_library_media_stats(section_id=None, refresh=False): plex = Plex(token=session.get_session_user_token()) libraries = Libraries() @@ -164,7 +164,8 @@ def get_library_media_stats(section_id=None): # Import media info cache from json file _, cached_library_media_stats, _ = libraries._load_data_from_cache(section_id=section_id, path='media_stats') - if not cached_library_media_stats: + _live_data = not cached_library_media_stats or refresh + if _live_data: library = plex.get_library(section_id) if library is None: @@ -172,9 +173,9 @@ def get_library_media_stats(section_id=None): return default_return library_media_stats = { - 'total_size': cached_library_media_stats.get('total_size', 0) if cached_library_media_stats else library.totalSize, - 'total_storage': cached_library_media_stats.get('total_storage', 0) if cached_library_media_stats else library.totalStorage, - 'total_duration': cached_library_media_stats.get('total_duration', 0) if cached_library_media_stats else library.totalDuration + 'total_size': library.totalSize if _live_data else cached_library_media_stats.get('total_size', 0), + 'total_storage': library.totalStorage if _live_data else cached_library_media_stats.get('total_storage', 0), + 'total_duration': library.totalDuration if _live_data else cached_library_media_stats.get('total_duration', 0) } libraries._save_data_to_cache(section_id=section_id, rows=library_media_stats, path='media_stats') diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 833a8d9b..b00036f6 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -704,12 +704,13 @@ class WebInterface(object): @cherrypy.tools.json_out() @requireAuth(member_of("admin")) @addtoapi() - def get_library_media_stats(self, section_id=None): + def get_library_media_stats(self, section_id=None, refresh=''): """ Get the media stats of a library section on Tautulli. ``` Required parameters: section_id (str): The id of the Plex library section + refresh (str): "true" to force a refresh of the stats Optional parameters: None @@ -722,9 +723,14 @@ class WebInterface(object): } ``` """ + + if helpers.bool_true(refresh): + refresh = True + else: + refresh = False logger.info("Getting library media stats for section %s.", section_id) - result = libraries.get_library_media_stats(section_id) + result = libraries.get_library_media_stats(section_id=section_id, refresh=refresh) return result