From 4530e816b0243618f3e46310a05bdb7362393072 Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Thu, 25 Mar 2021 19:21:58 -0700 Subject: [PATCH] Add last_accessed to get_library response --- plexpy/libraries.py | 34 ++++++++++++++++++++++------------ plexpy/webserve.py | 1 + 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/plexpy/libraries.py b/plexpy/libraries.py index 1e1f69ea..b41e9509 100644 --- a/plexpy/libraries.py +++ b/plexpy/libraries.py @@ -787,7 +787,8 @@ class Libraries(object): 'do_notify': 0, 'do_notify_created': 0, 'keep_history': 1, - 'deleted_section': 0 + 'deleted_section': 0, + 'last_accessed': None, } if not section_id: @@ -826,18 +827,26 @@ class Libraries(object): try: if str(section_id).isdigit(): - query = 'SELECT id AS row_id, server_id, section_id, section_name, section_type, ' \ - 'count, parent_count, child_count, ' \ - '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]) + where = 'library_sections.section_id = ?' + args = [section_id] 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: - 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 = [] library_details = {} @@ -869,7 +878,8 @@ class Libraries(object): 'do_notify': item['do_notify'], 'do_notify_created': item['do_notify_created'], 'keep_history': item['keep_history'], - 'deleted_section': item['deleted_section'] + 'deleted_section': item['deleted_section'], + 'last_accessed': item['last_accessed'] } return library_details diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 0f51de71..0deab8c9 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -971,6 +971,7 @@ class WebInterface(object): "do_notify_created": 1, "is_active": 1, "keep_history": 1, + "last_accessed": 1462693216, "library_art": "/:/resources/movie-fanart.jpg", "library_thumb": "/:/resources/movie.png", "parent_count": null,