refresh for library page

This commit is contained in:
herby2212 2023-10-29 19:51:00 +01:00
parent 2689646f54
commit 31f5dcd9da
3 changed files with 21 additions and 9 deletions

View file

@ -862,16 +862,20 @@ DOCUMENTATION :: END
} }
$(document).ready(function () { $(document).ready(function () {
loadLibraryMediaStats();
});
function loadLibraryMediaStats(refresh) {
// Populate media stats // Populate media stats
$.ajax({ $.ajax({
url: 'get_library_media_stats', url: 'get_library_media_stats',
data: { section_id: section_id }, data: { section_id: section_id, refresh: refresh },
complete: function(xhr, status) { complete: function(xhr, status) {
$("#info-element-total-runtime").html(humanDuration(xhr.responseJSON.total_duration)); $("#info-element-total-runtime").html(humanDuration(xhr.responseJSON.total_duration));
$("#info-element-total-storage").html(humanFileSize(xhr.responseJSON.total_storage)); $("#info-element-total-storage").html(humanFileSize(xhr.responseJSON.total_storage));
} }
}); });
}); }
$('#nav-tabs-mediainfo').on('shown.bs.tab', function() { $('#nav-tabs-mediainfo').on('shown.bs.tab', function() {
if (typeof(media_info_table) === 'undefined') { if (typeof(media_info_table) === 'undefined') {
@ -884,6 +888,7 @@ DOCUMENTATION :: END
refresh_table = true; refresh_table = true;
refresh_child_tables = true; refresh_child_tables = true;
media_info_table.draw(); media_info_table.draw();
loadLibraryMediaStats(true);
refresh_table = false; refresh_table = false;
}); });

View file

@ -143,7 +143,7 @@ def has_library_type(section_type):
result = monitor_db.select_single(query=query, args=args) result = monitor_db.select_single(query=query, args=args)
return bool(result) 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()) plex = Plex(token=session.get_session_user_token())
libraries = Libraries() libraries = Libraries()
@ -164,7 +164,8 @@ def get_library_media_stats(section_id=None):
# Import media info cache from json file # Import media info cache from json file
_, cached_library_media_stats, _ = libraries._load_data_from_cache(section_id=section_id, path='media_stats') _, 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) library = plex.get_library(section_id)
if library is None: if library is None:
@ -172,9 +173,9 @@ def get_library_media_stats(section_id=None):
return default_return return default_return
library_media_stats = { library_media_stats = {
'total_size': cached_library_media_stats.get('total_size', 0) if cached_library_media_stats else library.totalSize, 'total_size': library.totalSize if _live_data else cached_library_media_stats.get('total_size', 0),
'total_storage': cached_library_media_stats.get('total_storage', 0) if cached_library_media_stats else library.totalStorage, 'total_storage': library.totalStorage if _live_data else cached_library_media_stats.get('total_storage', 0),
'total_duration': cached_library_media_stats.get('total_duration', 0) if cached_library_media_stats else library.totalDuration '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') libraries._save_data_to_cache(section_id=section_id, rows=library_media_stats, path='media_stats')

View file

@ -704,12 +704,13 @@ class WebInterface(object):
@cherrypy.tools.json_out() @cherrypy.tools.json_out()
@requireAuth(member_of("admin")) @requireAuth(member_of("admin"))
@addtoapi() @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. """ Get the media stats of a library section on Tautulli.
``` ```
Required parameters: Required parameters:
section_id (str): The id of the Plex library section section_id (str): The id of the Plex library section
refresh (str): "true" to force a refresh of the stats
Optional parameters: Optional parameters:
None 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) 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 return result