From c70cc535e55227ea09c9fa062c9fe86376b41106 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Sat, 13 Oct 2018 17:23:36 -0700 Subject: [PATCH] Add library agent to database --- plexpy/__init__.py | 11 ++++++++++- plexpy/libraries.py | 6 ++++-- plexpy/pmsconnect.py | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/plexpy/__init__.py b/plexpy/__init__.py index d0e16f6c..7f1329b1 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -645,7 +645,7 @@ def dbcheck(): # library_sections table :: This table keeps record of the servers library sections c_db.execute( 'CREATE TABLE IF NOT EXISTS library_sections (id INTEGER PRIMARY KEY AUTOINCREMENT, ' - 'server_id TEXT, section_id INTEGER, section_name TEXT, section_type TEXT, ' + 'server_id TEXT, section_id INTEGER, section_name TEXT, section_type TEXT, agent TEXT, ' 'thumb TEXT, custom_thumb_url TEXT, art TEXT, count INTEGER, parent_count INTEGER, child_count INTEGER, ' 'do_notify INTEGER DEFAULT 1, do_notify_created INTEGER DEFAULT 1, keep_history INTEGER DEFAULT 1, ' 'deleted_section INTEGER DEFAULT 0, UNIQUE(server_id, section_id))' @@ -1663,6 +1663,15 @@ def dbcheck(): except sqlite3.OperationalError: logger.warn(u"Unable to remove duplicate libraries from library_sections table.") + # Upgrade library_sections table from earlier versions + try: + c_db.execute('SELECT agent FROM library_sections') + except sqlite3.OperationalError: + logger.debug(u"Altering database. Updating database table library_sections.") + c_db.execute( + 'ALTER TABLE library_sections ADD COLUMN agent TEXT' + ) + # Upgrade users table from earlier versions (remove UNIQUE constraint on username) try: result = c_db.execute('SELECT SQL FROM sqlite_master WHERE type="table" AND name="users"').fetchone() diff --git a/plexpy/libraries.py b/plexpy/libraries.py index cdf48910..2e98ddff 100644 --- a/plexpy/libraries.py +++ b/plexpy/libraries.py @@ -50,6 +50,7 @@ def refresh_libraries(): 'section_id': section['section_id'], 'section_name': section['section_name'], 'section_type': section['section_type'], + 'agent': section['agent'], 'thumb': section['thumb'], 'art': section['art'], 'count': section['count'], @@ -923,7 +924,7 @@ class Libraries(object): monitor_db = database.MonitorDatabase() try: - query = 'SELECT section_id, section_name, section_type FROM library_sections WHERE deleted_section = 0' + query = 'SELECT section_id, section_name, section_type, agent FROM library_sections WHERE deleted_section = 0' result = monitor_db.select(query=query) except Exception as e: logger.warn(u"Tautulli Libraries :: Unable to execute database query for get_sections: %s." % e) @@ -933,7 +934,8 @@ class Libraries(object): for item in result: library = {'section_id': item['section_id'], 'section_name': item['section_name'], - 'section_type': item['section_type'] + 'section_type': item['section_type'], + 'agent': item['agent'] } libraries.append(library) diff --git a/plexpy/pmsconnect.py b/plexpy/pmsconnect.py index d312ec90..ea6315ca 100644 --- a/plexpy/pmsconnect.py +++ b/plexpy/pmsconnect.py @@ -2290,6 +2290,7 @@ class PmsConnect(object): libraries_output = {'section_id': helpers.get_xml_attr(result, 'key'), 'section_type': helpers.get_xml_attr(result, 'type'), 'section_name': helpers.get_xml_attr(result, 'title'), + 'agent': helpers.get_xml_attr(result, 'agent'), 'thumb': helpers.get_xml_attr(result, 'thumb'), 'art': helpers.get_xml_attr(result, 'art') } @@ -2450,6 +2451,7 @@ class PmsConnect(object): library_stats = {'section_id': section_id, 'section_name': library['section_name'], 'section_type': section_type, + 'agent': library['agent'], 'thumb': library['thumb'], 'art': library['art'], 'count': children_list['library_count']