mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-16 02:02:58 -07:00
Add last_refreshed time to get_library_media_info response
This commit is contained in:
parent
c90469b0b7
commit
000656be00
1 changed files with 29 additions and 13 deletions
|
@ -458,7 +458,8 @@ class Libraries(object):
|
||||||
'draw': 0,
|
'draw': 0,
|
||||||
'data': [],
|
'data': [],
|
||||||
'filtered_file_size': 0,
|
'filtered_file_size': 0,
|
||||||
'total_file_size': 0}
|
'total_file_size': 0,
|
||||||
|
'last_refreshed': None}
|
||||||
|
|
||||||
if not session.allow_session_library(section_id):
|
if not session.allow_session_library(section_id):
|
||||||
return default_return
|
return default_return
|
||||||
|
@ -513,13 +514,19 @@ class Libraries(object):
|
||||||
watched_list[str(item[group_by])] = {'last_played': item['last_played'],
|
watched_list[str(item[group_by])] = {'last_played': item['last_played'],
|
||||||
'play_count': item['play_count']}
|
'play_count': item['play_count']}
|
||||||
|
|
||||||
|
cache_time = None
|
||||||
rows = []
|
rows = []
|
||||||
# Import media info cache from json file
|
# Import media info cache from json file
|
||||||
if rating_key:
|
if rating_key:
|
||||||
try:
|
try:
|
||||||
inFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info_%s-%s.json' % (section_id, rating_key))
|
inFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info_%s-%s.json' % (section_id, rating_key))
|
||||||
with open(inFilePath, 'r') as inFile:
|
with open(inFilePath, 'r') as inFile:
|
||||||
rows = json.load(inFile)
|
data = json.load(inFile)
|
||||||
|
if isinstance(data, dict):
|
||||||
|
cache_time = data['last_refreshed']
|
||||||
|
rows = data['rows']
|
||||||
|
else:
|
||||||
|
rows = data
|
||||||
library_count = len(rows)
|
library_count = len(rows)
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
#logger.debug("Tautulli Libraries :: No JSON file for rating_key %s." % rating_key)
|
#logger.debug("Tautulli Libraries :: No JSON file for rating_key %s." % rating_key)
|
||||||
|
@ -529,7 +536,12 @@ class Libraries(object):
|
||||||
try:
|
try:
|
||||||
inFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info_%s.json' % section_id)
|
inFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info_%s.json' % section_id)
|
||||||
with open(inFilePath, 'r') as inFile:
|
with open(inFilePath, 'r') as inFile:
|
||||||
rows = json.load(inFile)
|
data = json.load(inFile)
|
||||||
|
if isinstance(data, dict):
|
||||||
|
cache_time = data['last_refreshed']
|
||||||
|
rows = data['rows']
|
||||||
|
else:
|
||||||
|
rows = data
|
||||||
library_count = len(rows)
|
library_count = len(rows)
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
#logger.debug("Tautulli Libraries :: No JSON file for library section_id %s." % section_id)
|
#logger.debug("Tautulli Libraries :: No JSON file for library section_id %s." % section_id)
|
||||||
|
@ -594,18 +606,20 @@ class Libraries(object):
|
||||||
return default_return
|
return default_return
|
||||||
|
|
||||||
# Cache the media info to a json file
|
# Cache the media info to a json file
|
||||||
|
cache_time = helpers.timestamp()
|
||||||
|
|
||||||
if rating_key:
|
if rating_key:
|
||||||
try:
|
try:
|
||||||
outFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info_%s-%s.json' % (section_id, rating_key))
|
outFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info_%s-%s.json' % (section_id, rating_key))
|
||||||
with open(outFilePath, 'w') as outFile:
|
with open(outFilePath, 'w') as outFile:
|
||||||
json.dump(rows, outFile)
|
json.dump({'last_refreshed': cache_time, 'rows': rows}, outFile)
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
logger.debug("Tautulli Libraries :: Unable to create cache file for rating_key %s." % rating_key)
|
logger.debug("Tautulli Libraries :: Unable to create cache file for rating_key %s." % rating_key)
|
||||||
elif section_id:
|
elif section_id:
|
||||||
try:
|
try:
|
||||||
outFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info_%s.json' % section_id)
|
outFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info_%s.json' % section_id)
|
||||||
with open(outFilePath, 'w') as outFile:
|
with open(outFilePath, 'w') as outFile:
|
||||||
json.dump(rows, outFile)
|
json.dump({'last_refreshed': cache_time, 'rows': rows}, outFile)
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
logger.debug("Tautulli Libraries :: Unable to create cache file for section_id %s." % section_id)
|
logger.debug("Tautulli Libraries :: Unable to create cache file for section_id %s." % section_id)
|
||||||
|
|
||||||
|
@ -662,15 +676,17 @@ class Libraries(object):
|
||||||
|
|
||||||
filtered_file_size = sum([helpers.cast_to_int(d['file_size']) for d in results])
|
filtered_file_size = sum([helpers.cast_to_int(d['file_size']) for d in results])
|
||||||
|
|
||||||
dict = {'recordsFiltered': filtered_count,
|
output = {
|
||||||
'recordsTotal': library_count,
|
'recordsFiltered': filtered_count,
|
||||||
'data': results,
|
'recordsTotal': int(library_count),
|
||||||
'draw': int(json_data['draw']),
|
'data': results,
|
||||||
'filtered_file_size': filtered_file_size,
|
'draw': int(json_data['draw']),
|
||||||
'total_file_size': total_file_size
|
'filtered_file_size': filtered_file_size,
|
||||||
}
|
'total_file_size': total_file_size,
|
||||||
|
'last_refreshed': cache_time
|
||||||
|
}
|
||||||
|
|
||||||
return dict
|
return output
|
||||||
|
|
||||||
def get_media_info_file_sizes(self, section_id=None, rating_key=None):
|
def get_media_info_file_sizes(self, section_id=None, rating_key=None):
|
||||||
if not session.allow_session_library(section_id):
|
if not session.allow_session_library(section_id):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue