Add last_accessed to get_library response

This commit is contained in:
JonnyWong16 2021-03-25 19:21:58 -07:00
parent b6f4c2e945
commit 4530e816b0
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
2 changed files with 23 additions and 12 deletions

View file

@ -787,7 +787,8 @@ class Libraries(object):
'do_notify': 0, 'do_notify': 0,
'do_notify_created': 0, 'do_notify_created': 0,
'keep_history': 1, 'keep_history': 1,
'deleted_section': 0 'deleted_section': 0,
'last_accessed': None,
} }
if not section_id: if not section_id:
@ -826,18 +827,26 @@ class Libraries(object):
try: try:
if str(section_id).isdigit(): if str(section_id).isdigit():
query = 'SELECT id AS row_id, server_id, section_id, section_name, section_type, ' \ where = 'library_sections.section_id = ?'
'count, parent_count, child_count, ' \ args = [section_id]
'thumb AS library_thumb, custom_thumb_url AS custom_thumb, art AS library_art, ' \
'custom_art_url AS custom_art, is_active, ' \
'do_notify, do_notify_created, keep_history, deleted_section ' \
'FROM library_sections ' \
'WHERE section_id = ? AND server_id = ? '
result = monitor_db.select(query, args=[section_id, server_id])
else: else:
result = [] raise Exception('Missing section_id')
query = 'SELECT library_sections.id AS row_id, server_id, library_sections.section_id, ' \
'section_name, section_type, ' \
'count, parent_count, child_count, ' \
'library_sections.thumb AS library_thumb, custom_thumb_url AS custom_thumb, ' \
'library_sections.art AS library_art, ' \
'custom_art_url AS custom_art, is_active, ' \
'do_notify, do_notify_created, keep_history, deleted_section, ' \
'MAX(session_history.started) AS last_accessed ' \
'FROM library_sections ' \
'JOIN session_history_metadata ON library_sections.section_id == session_history_metadata.section_id ' \
'JOIN session_history ON session_history_metadata.id == session_history.id ' \
'WHERE %s AND server_id = ? ' % where
result = monitor_db.select(query, args=args + [server_id])
except Exception as e: except Exception as e:
logger.warn("Tautulli Libraries :: Unable to execute database query for get_details: %s." % e) logger.warn("Tautulli Libraries :: Unable to execute database query for get_library_details: %s." % e)
result = [] result = []
library_details = {} library_details = {}
@ -869,7 +878,8 @@ class Libraries(object):
'do_notify': item['do_notify'], 'do_notify': item['do_notify'],
'do_notify_created': item['do_notify_created'], 'do_notify_created': item['do_notify_created'],
'keep_history': item['keep_history'], 'keep_history': item['keep_history'],
'deleted_section': item['deleted_section'] 'deleted_section': item['deleted_section'],
'last_accessed': item['last_accessed']
} }
return library_details return library_details

View file

@ -971,6 +971,7 @@ class WebInterface(object):
"do_notify_created": 1, "do_notify_created": 1,
"is_active": 1, "is_active": 1,
"keep_history": 1, "keep_history": 1,
"last_accessed": 1462693216,
"library_art": "/:/resources/movie-fanart.jpg", "library_art": "/:/resources/movie-fanart.jpg",
"library_thumb": "/:/resources/movie.png", "library_thumb": "/:/resources/movie.png",
"parent_count": null, "parent_count": null,