mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-15 01:32:57 -07:00
refresh for library page
This commit is contained in:
parent
2689646f54
commit
31f5dcd9da
3 changed files with 21 additions and 9 deletions
|
@ -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;
|
||||
});
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
@ -723,8 +724,13 @@ 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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue